import collections
def sortFirst(val):
    return val[0]
N=raw_input("")
N=int(N)
l={}
for i in range(1,N+1):
    S,P = raw_input("").split(' ')
    if S in l.keys():
        l[S].append([int(P),i])

    else:
        l[S]=[[int(P),i]]


for key in l.keys():
    l[key].sort(key=sortFirst,reverse=True)
for key in sorted(l):
    for val in l[key]:
        print "%d"%(val[1])
