#include <iostream>
#include <fstream>
#include <cstring>
#include <map>
#include <algorithm>
#include <vector>

using namespace std;

ifstream f ("input.in");

int id_crt;
map <string, int> id;
map <int, string> ec;
pair <string, pair <int, int> > echipa[10]; //first = scor, second = goluri

void citeste() {
    string a, b;
    int scor_a, scor_b;
    int id1, id2;

    while (cin >> a) {
        cin >> b;
        cin >> scor_a >> scor_b;

        if (id.find(a) == id.end()) {id_crt++; id.insert(make_pair(a, id_crt)); echipa[id_crt].first = a;}
        if (id.find(b) == id.end()) {id_crt++; id.insert(make_pair(b, id_crt)); echipa[id_crt].first = b;}

        id1 = id[a];
        id2 = id[b];

        //cout << a << ' ' << id1 << endl << b << ' ' <<  id2 << endl;

      //  cout << id1 << ' ' << id2 << endl;

        echipa[id1].second.second += scor_a;
        echipa[id2].second.second += scor_b;

        if (scor_a == scor_b) {
           echipa[id1].second.first++;
           echipa[id2].second.first++;
        }
        else if (scor_a > scor_b) echipa[id1].second.first += 3;
        else echipa[id2].second.first += 3;
    }

}

inline bool conditie(pair < string, pair <int, int> > a, pair <string, pair <int, int> > b) {
    if (a.second.first > b.second.first) return true;
    if (a.second.first < b.second.first) return false;
    if (a.second.second > b.second.second) return true;
    if (a.second.second < b.second.second) return false;
    return (a.first > b.first);
}

/*

teams are sorted decreasingly by the number of points they accumulate;
in case of equal points, multiple teams are sorted decreasingly by the total number of goals they have scored;
in case of equal points and equal goals, multiple teams are sorted alphabetically, in ascending order.
*/

void scrie() {
    for (int i = 1; i <= 4; i++) cout << echipa[i].first << '\n';
}

int main() {
    citeste();
    sort (echipa + 1, echipa + id_crt + 1, conditie);
    scrie();
}