n = int(input())
# 用来存所有的学生信息
stu_infos = []
min_score = 101
max_score = 0
min_number = -1
max_number = -1
for i in range(n):
# 依次输入每个学生的信息
student_info = input()
# 将输入的学生信息按空格进行分割并加入到列表中
stu_infos.append(student_info.split(' '))
for i in range(n):
num = int(stu_infos[i][2])
if num > max_score:
max_score = num
max_number = i
if num < min_score:
min_score = num
min_number = i
print(stu_infos[max_number][0] + " " + stu_infos[max_number][1])
print(stu_infos[min_number][0] + " " + stu_infos[min_number][1], end="")