import sys
newCase = True
for line in sys.stdin:
if newCase:
newCase = False
N = int(line)
rats = list()
else:
N-=1
weight, color = line.split()
rats.append((int(weight),color))
if N==0:
newCase=True
rats.sort(key=lambda x:x[0],reverse=True)
for rat in rats:
print(rat[1])