#include<stdio.h>
#include <iostream>
#include <locale>
#include<string>
using namespace std;
string names[4];
int goals[4],score[4];
int lowercase(char ch){
    if(ch<='Z')
        return ch+32;
    return ch;
}
int main()
{
  //  freopen("tour.in","r",stdin);
 //   freopen("tour.out","w",stdout);
    int i,nr=0;
    for(i=0; i<4; i++)
    {
        string tname,test;
        cin>>tname;
        test=tname;
        int j=0,poz1=-1;
        while(j<nr)
        {
            if(names[j]==tname)
                poz1=j;
            j++;
        }
        if(poz1==-1)
        {
            poz1=nr;
            names[nr++]=tname;
        }
        cin>>tname;
        j=0;
        int poz2=-1;
        while(j<nr)
        {
            if(names[j]==tname)
                poz2=j;
            j++;
        }
        if(poz2==-1)
        {
            poz2=nr;
            names[nr++]=tname;
        }
        int s1,s2;
        scanf("%d%d",&s1,&s2);
        goals[poz1]+=s1;
        goals[poz2]+=s2;
        if(s1>s2)
            score[poz1]+=3;
        else if(s2>s1)
            score[poz2]+=3;
        else
        {
            score[poz1]++;
            score[poz2]++;
        }
    }
    int j;
   // for(i=0; i<4; i++)
   //     cout<<names[i]<<" "<<goals[i]<<" "<<score[i]<<"\n";
    for(i=0; i<4; i++)
        for(j=i+1; j<4; j++)
        {
            if(score[i]<score[j])
            {
                swap(score[i],score[j]);
                swap(goals[i],goals[j]);
                swap(names[i],names[j]);
            }
            else if(score[i]==score[j]&&goals[i]!=goals[j])
            {
                if(goals[i]<goals[j])
                {
                    swap(score[i],score[j]);
                    swap(goals[i],goals[j]);
                    swap(names[i],names[j]);
                }
            }
            else if(score[i]==score[j]&&goals[i]==goals[j])
            {
                int rez=0;
                string::size_type jj=0;
                while(jj<names[i].length()&&jj<names[j].length())
                {
                    char c1=names[i][jj],c2=names[j][jj];
                    c1=lowercase(c1);
                    c2=lowercase(c2);
                    if(c1<c2)
                    {
                        rez=-1;
                        jj=names[i].length();
                    }
                    if(c2<c1)
                    {
                        rez=1;
                        jj=names[i].length();
                    }
                    jj++;
                }
                if(rez==-1)
                {
                    swap(score[i],score[j]);
                    swap(goals[i],goals[j]);
                    swap(names[i],names[j]);
                }
            }
        }
    for(i=0; i<4; i++)
    {
        cout<<names[i]<<"\n";
    }
    return 0;
}