from operator import itemgetter, attrgetter

l = []

class Team(object):
    def __init__(self, n, p, g):
        self.name = n
        self.point = p
        self.goal = g
        
    def add(self, point, goal):
        self.point += point
        self.goal += goal



def Add(name, point, goal):
    f = False
    for t in l:
        if name == t.name:
            t.add(point, goal)
            f = True
            break
    if not f:
        team = Team(name, point, goal)
        l.append(team)

if __name__ == '__main__':
    for i in range(6):
        s = raw_input("")
        ch = s.split(" ")
        
        if int(ch[2]) > int(ch[3]):
            Add(ch[0], 3, int(ch[2]))
            Add(ch[1], 0, int(ch[3]))
        elif int(ch[2]) == int(ch[3]):
            Add(ch[0], 1, int(ch[2]))
            Add(ch[1], 1, int(ch[3]))
        elif int(ch[2]) < int(ch[3]):
            Add(ch[0], 0, int(ch[2]))
            Add(ch[1], 3, int(ch[3]))
            
    l = sorted(l, key = lambda team: team.name)
    l = sorted(l, key = lambda team: team.goal, reverse = True)
    l = sorted(l, key = lambda team: team.point, reverse = True)



    for t in l:
        print t.name