#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

int main() {
  map<string, pair<int, int> > m;

  for (int i = 1; i <= 6; i += 1) {
    string teamA, teamB;
    int gA, gB;
    cin >> teamA >> teamB >> gA >> gB;

    int pA = 0, pB = 0;
    if (gA > gB) {
      pA = 3;
    } else if (gA < gB) {
      pB = 3;
    } else {
      pA = pB = 1;
    }

    pair<int, int> pgA, pgB;
    pgA = m[teamA];
    pgB = m[teamB];

    m[teamA] = make_pair(pgA.first + pA, pgA.second + gA);
    m[teamB] = make_pair(pgB.first + pB, pgB.second + gB);
  }

  vector<pair< pair<int, int>, string > > sB;
  for (auto kv: m) {
    sB.push_back(make_pair(kv.second, kv.first));
  }

  sort(sB.begin(), sB.end(), greater<pair< pair<int, int>, string > >());

  for (auto t: sB) {
    cout << t.second << '\n';
  }

  return 0;
}