# 3등 찾기

num=int(input())
scores=[]
for i in range(num):
    name,score=input().split()
    scores.append((name,int(score)))

scores.sort(key=lambda score:score[1],reverse=True)
print(scores[2][0])


856dd7f52bcd0b5b2334c0041c26b73105661821
<mask token>

<mask token>
for i in range(num):
    name, score = input().split()
    scores.append((name, int(score)))
scores.sort(key=lambda score: score[1], reverse=True)
print(scores[2][0])

num = int(input())
scores = []
for i in range(num):
    name, score = input().split()
    scores.append((name, int(score)))
scores.sort(key=lambda score: score[1], reverse=True)
print(scores[2][0])

# 3등 찾기

num=int(input())
scores=[]
for i in range(num):
    name,score=input().split()
    scores.append((name,int(score)))

scores.sort(key=lambda score:score[1],reverse=True)
print(scores[2][0])

