#! /usr/bin/python

import sys

teams = {}
for line in sys.stdin:
    line = line.strip()
    teamA, teamB, goalsA, goalsB = line.split()
    goalsA = int(goalsA)
    goalsB = int(goalsB)
    pointsA, pointsB = 1, 1
    if goalsA > goalsB:
        pointsA, pointsB = 3, 0
    elif goalsA < goalsB:
        pointsA, pointsB = 0, 3
    if teamA not in teams:
        teams[teamA] = [pointsA, goalsA, teamA]
    else:
        teams[teamA][0] += pointsA
        teams[teamA][1] += goalsA
    if teamB not in teams:
        teams[teamB] = [pointsB, goalsB, teamB]
    else:
        teams[teamB][0] += pointsB
        teams[teamB][1] += goalsB
for team in sorted(teams, key=lambda x:teams[x], reverse=True):
    print team