#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
struct team{
    int number, score;
};
team v[5];
char d[4][101],s[255];
int main()
{
    int ok;
    int team_one,team_two,k=-1,s1,s2;
    for(int i=1;i<=6;i++){
        cin>>s;
        ok = -1;
        for(int j=0;j<=3 && ok == -1;j++)
            if(strcmp(s,d[j])){
                ok = i;
            }
        if(ok == -1){
            k++;
            strcpy(d[k],s);
            d[k][strlen(s)] = '\0';
            v[k].number = k;
            team_one = k;
        }
        else{
            team_one = ok;
        }
        strcpy(s,"");
        cin>>s;
        ok = -1;
        for(int j=0;j<=3 && ok == -1;j++)
            if(strcmp(s,d[j])){
                ok = i;
            }
            if(ok == -1){
                k++;
                strcpy(d[k],s);
                d[k][strlen(s)] = '\0';
                v[k].number = k;
                team_two = k;
            }
            else{
            team_two = ok;
            }
            strcpy(s,"");
            cin>>s1>>s2;
            if( s1 > s2)
                v[team_one].score+=3;
            else if( s1 == s2){
                v[team_two].score++;
                v[team_one].score++;
            }
            else
                v[team_two].score+=3;

    }
    ok = 0;
    while( ok == 0){
        ok = 1;
        for(int i=0;i<3;i++)
            if(v[i].score < v[i+1].score){
               swap( v[i],v[i+1]);
               ok = 0;
            }

    }
    int nm;
    for(int i=0;i<=3;i++){
        nm = v[i].number;
        for(int j = 0;j<100;j++)
            cout<<d[nm][j];
        cout<<'\n';
    }
    return 0;
}