#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <functional>
#include <tuple>

#include <cassert>
#include <cstdlib>

using namespace std;


int main() {
    //assert(freopen("test.in", "r", stdin) && freopen("test.out", "w", stdout));
    ios::sync_with_stdio(0);
    map<string, int> points, goals;
    string t1, t2;
    int s1, s2;
    for (int i = 0; i < 6; i++) {
        cin >> t1 >> t2 >> s1 >> s2;
        //cout << t1 << " " << t2 << "\n";
        if (s1 == s2) {
            points[t1]++;
            points[t2]++;
        } else
        if (s1 > s2) {
            points[t1] += 3;
        } else {
            points[t2] += 3;
        }
        if (points[t1] == 0) points[t1] = 0;
        if (points[t2] == 0) points[t2] = 0;

        goals[t1] += s1;
        goals[t2] += s2;
    }
    vector< tuple<int,int,string> > teams;
    for (auto& t : points) {
        teams.push_back(make_tuple(points[t.first], goals[t.first], t.first));
    }

    sort( begin(teams), end(teams), [](const tuple<int,int,string>& a,const tuple<int,int,string>& b) {
        int p1, p2, s1, s2;
        string t1, t2;
        tie(p1, s1, t1) = a;
        tie(p2, s2, t2) = b;
        if (p1 == p2) {
            if (s1 == s2) {
                return t1 < t2;
            }
            return s1 > s2; 
        }
        return p1 > p2;
    });

    for (auto& team : teams) {
        cout << get<2>(team) << "\n";
    }
    return 0;
}