from operator import attrgetter class Team: def __init__(self, name, points, goals): self.name = name self.points = points self.goals = goals def compare(self, team): if self.points > team.points: return 1 elif self.points < team.points: return 0 elif self.points == team.points: if self.goals > team.goals: return 1 elif self.goals < team.goals: return 0 elif self.goals == team.goals: if self.name > team.name: return 1 elif self.name < team.name: return 0 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=attrgetter('points', 'goals', 'name'), reverse=True) for t in sorted_teams: print t.name