#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <cmath>
#include <fstream>
#include <cstring>
#include <bitset>
#include <stack>
#include <vector>
#include <map>
#include <set>

#define per pair<int,int>
#define x first
#define y second
#define DN 200000
#define DM 2000
using namespace std;

ifstream f("test.in");

set <string> st;
vector< pair<string,int> > t;
map <string,int> mp;

void read(){

    string x,y;
    int a,b;
    while(cin>>x>>y>>a>>b){

        st.insert(x);
        st.insert(y);
        if(a == b && a!=0){
            ++mp[x];
            ++mp[y];
        }
        if( a > b )
            mp[x]+=3;
        if( a < b)
            mp[y]+=3;
    }
}

bool cmp(pair<string,int> p1,pair<string,int> p2){

    if(p1.y == p2.y)
        return p1.x < p2.x;
    return p1.y > p2.y;
}

void solve(){

    for(set<string>::iterator it=st.begin();it!=st.end();++it){

        t.push_back(make_pair(*it,mp[*it]));
        //cout<<t.back().x<<" "<<t.back().y<<endl;
    }
    sort(t.begin(),t.end(),cmp);
    for(int i=0;i<t.size();++i)
        cout<<t[i].x<<"\n";
}

int main()
{
    read();
    solve();
    return 0;
}