#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <set>
#include <queue>
#include <map>
#define pii pair <int, int >
#define fi first
#define se second

using namespace std;
map < string ,int > goals;
map < string ,int > M;
map < string ,int > points;
struct str
{
    int p,g;
    string s;
    bool operator <(const str a)const{
        if(p==a.p)
        {
            if(g==a.g)
                return s < a.s;
            return g > a.g;
        }
        return p > a.p;
    }
};
vector < str >sol;
int main()
{
    //freopen("date.in","r",stdin);
    //freopen("date.out","w",stdout);
    cin.sync_with_stdio(false);
    string s1, s2;
    while(cin >> s1)
    {
        int x,y;
        cin >> s2;
        cin >> x >> y;
        if(x > y)
            points[s1] += 3;
        else
            if(y>x)
                points[s2] += 3;
            else
                points[s1]++,
                points[s2]++;
         goals[s1]+=x;
         goals[s2]+=y;
         M[s1] = 1;
         M[s2] = 1;

    }
    for(auto x=M.begin();x!=M.end();++x)
    {
        string s = x->fi;
        int p = points[s];
        int g = goals[s];
        str curent;
        curent.p = p;
        curent.g = g;
        curent.s = s;
        sol.push_back(curent);
    }
    sort(sol.begin(),sol.end());
    for(auto x=sol.begin();x!=sol.end();++x)
        cout<<x->s<<"\n";
    return 0;
}