m=int(input())
lst=[]
for i in range(m):
a,b,c=input().split()
b=tuple(map(int,b.split(":")))
c=tuple(map(int,c.split(":")))
lst.append((a,b,c))
#sorted排序之后仍是list。从小到大排序
out1=sorted(lst,key= lambda x:x[1])[0][0]
out2=sorted(lst,key= lambda x:x[2],reverse=True)[0][0]
print(out1,out2)