n = int(input())
dic = {}
for x in range(n):
  dic[x+1] = input().split()
ls = sorted(dic.items(), key=lambda x:x[1][0])

for y in range(1,n-1):
  
  if ls[y][1][0] == ls[y+1][1][0]:
    
    if ls[y][1][1] < ls[y+1][1][1]:
      
      ls[y+1],ls[y] = ls[y],ls[y+1]
    
    
for b in range(len(ls)):
  print(ls[b][0])
