from operator import attrgetter class Team: def __init__(self, name, points, goals): self.name = name self.points = points self.goals = goals @staticmethod def compare(team_a, team_b): if team_a.points > team_b.points: return 1 elif team_a.points < team_b.points: return -1 elif team_a.points == team_b.points: if team_a.goals > team_b.goals: return 1 elif team_a.goals < team_b.goals: return -1 elif team_a.goals == team_b.goals: if team_a.name > team_b.name: return 1 elif team_a.name < team_b.name: return -1 if __name__ == '__main__': teams = {} for _ in range(6): teamA, teamB, goalsA, goalsB = raw_input().split() goalsA, goalsB = int(goalsA), int(goalsB) if teamA not in teams: teams[teamA] = Team(teamA, 0, 0) if teamB not in teams: teams[teamB] = Team(teamB, 0, 0) if goalsA > goalsB: teams[teamA].points += 3 elif goalsA == goalsB: teams[teamA].points += 1 teams[teamB].points += 1 else: teams[teamB].points += 3 teams[teamA].goals += goalsA teams[teamB].goals += goalsB sorted_teams = sorted(teams.values(), key=lambda x: ()) for t in sorted_teams: print t.name