import sys

class Team(object):
    pass


testing = False

if testing:
	data = open("test.txt").readlines()
else:
	data = sys.stdin.readlines()

dict = {}

goals = {}

for line in data:

	line = line.split(" ")

	c1 = line[0]
	c2 = line[1]
	s1 = int(line[2])
	s2 = int(line[3])


	if not(c1 in dict):
		dict[c1] = 0
		goals[c1] = 0

	if not(c2 in dict):
		dict[c2] = 0
		goals[c2] = 0

	if s1 == s2:
		dict[c1] += 1
		dict[c2] += 1


	if s1 > s2:
		dict[c1] += 3


	if s1 < s2:
		dict[c2] += 3	

	goals[c1] += s1
	goals[c2] += s2


teams = []
for key in dict:

	team = Team()
	team.name = key
	team.goals = goals[key]
	team.rating = dict[key]
	teams.append(team)


def sortF(t1,t2):


	if t1.rating != t2.rating:

		return -1 if t1.rating > t2.rating else 1

	if t1.goals != t2.goals:
		return -1 if t1.goals > t2.goals else 1

	return -1 if t1.name > t2.name else 1

teams.sort(sortF)

for name in map(lambda x : x.name, teams):
	print name