lst = []
while True:
n = input()
if not n:
break
lst.append(n.split())
lst = sorted(lst, key=lambda x:x[1], reverse=True)
#print(lst)
with open('result.txt', 'w') as f:
for i in lst[:3]:
f.write(i[0]+'\n')
Mike 2019001 Bob 2019002 Lily 2019004 Lucy 2019003 John 2019005