#include <bits/stdc++.h>
using namespace std;
struct abc{
    string team;
    int p,g;
}a[5];
bool comp(abc x,abc y)
{
    if(x.p!=y.p)return x.p < y.p;
    else if(x.g!=y.g)return x.g < y.g;
    else return x.team.compare(y.team) > 0;
}
string s1,s2;
int main()
{
    int x,y,xx,yy;
    cin>>s1>>s2>>x>>y;
    a[1].team=s1;a[1].g=x;
    a[2].team=s2;a[2].g=y;
    if(x==y)a[1].p=a[2].p=1;
    else if(x>y)a[1].p=3;
    else a[2].p=3;
    cin>>s1>>s2>>x>>y;
    a[3].team=s1;a[3].g=x;
    a[4].team=s2;a[4].g=y;
    if(x==y)a[3].p=a[4].p=1;
    else if(x>y)a[3].p=3;
    else a[4].p=3;
    for(int i=1;i<=4;i++)
    {
        cin>>s1>>s2>>x>>y;
        xx=x;yy=y;
        if(x==y)x=y=1;
        else if(x>y)x=3,y=0;
        else y=3,x=0;
        for(int j=1;j<=4;j++)
        {
            if(a[j].team.compare(s1)==0)a[j].p+=x,a[j].g+=xx;
            else if(a[j].team.compare(s2)==0)a[j].p+=y,a[j].g+=yy;
        }
    }
    sort(a+1,a+5,comp);
    for(int i=4;i>=1;i--)cout<<a[i].team<<'\n';
    return 0;
}