from sys import argv

debug = "a" in argv
n = int(input())
ls = []
la = ls.append
for i in range(1, n + 1):
    s = input().split()
    la((i, s[0], int(s[1])))
if debug:
    print("ls:",ls)
ls = sorted(ls, key=lambda x: x[2], reverse=1)
ls = sorted(ls, key=lambda x: x[1])
if debug:
    print("ls(sorted):",ls)
if debug:
    print("debug end")
for x in ls:
    print(x[0])