n = input()
n = int(n)
name, number, score = input().split()
score = int(score)
score_max = score_min = score
name_min = name_max = name
number_max = number_min = number
n = n - 1
while n > 0:
n -= 1
name, number, score = input().split()
score = int(score)
if score > score_max:
score_max = score
name_max = name
number_max = number
if score < score_min:
score_min = score
name_min = name
number_min = number
print(name_max, number_max)
print(name_min, number_min)