#include<stdio.h>
#include <iostream>
#include<string>
using namespace std;
string names[4];
int goals[4],score[4];
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++)
        for(j=0;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]&&names[j]>names[i]){
                         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;
}