# Codechef Problem #UCL
# 19th September 2019, 19:20 hours.
t = int(input())
for i in range(t):
teams = [] # This will store the name of teams
matches = [] # This will store the fixtures
scores = [0,0,0,0] # This will store the points of each team
gd = [0,0,0,0] # This will store the goal difference of each team
for i in range(12): # There are 12 matches everytime
# Taking inputs
test = input().strip().split() # Split inputs and get individual values
team1 = test[0]
score1 = test[1]
team2 = test[4]
score2 = test[3]
matches.append([team1,team2,score1,score2])
teams.append(team1)
teams.append(team2)
teams = set(teams) # Typecasted to set to avoid repetition
teams = list(teams) # Back to list
# Scoring system
for i in matches: # For each match
t1 = i[0] # Team No.1 playing in the match
t2 = i[1] # Team No.2 playing in the match
s1 = int(i[2]) # Score of Team No.1
s2 = int(i[3]) # Score of Team No.2
for j in teams:
if t1 == j:
index1 = teams.index(j) # Correspond to team1
if t2 == j:
index2 = teams.index(j) # Correspond to team2
if s1>s2: # Team1's score is greater than team2's score
scores[index1] += 3 # Add 3 points to Team1
gd[index1] += s1-s2 # Edit goal difference of Team1
gd[index2] += s2-s1 # Edit goal difference of team2
elif s1==s2: # Both teams' scores are equal
scores[index1] += 1 # Add 1 point to Team1
scores[index2] += 1 # Add 1 point to Team2
gd[index1] += s1-s2 # Edit goal difference of Team1
gd[index2] += s2-s1 # Edit goal difference of Team2
else: # Team2's score is greater than team1's score
scores[index2] += 3 # Add 3 points to Team1
gd[index1] += s1-s2 # Edit goal difference of Team1
gd[index2] += s2-s1 # Edit goal difference of Team2
maximum = max(scores) # Find maximum points
if scores.count(maximum) > 1: # If two or more teams have same max score
max1 = gd.index(max(gd)) # Judge through goal difference
gd[max1] = -100
max2 = gd.index(max(gd))
print(teams[max1],teams[max2])
else: #One team has more points than other
max1 = scores.index(max(scores)) # Find index of team having max pts
scores[max1] = 0 # Make it 0 to find next max
max2 = scores.index(max(scores)) # Find index of second max
print(teams[max1],teams[max2])