import numpy as np
N=int(input())
a=[]
for i in range(N):
    s,p=input().split()
    p=int(p)
    a.append([s,p,i+1])
a.sort(key=lambda x:(x[0],x[1]))
i=0
while i<=N:
    last=a[i][0]
    i+=1
    if i<N and last==a[i][0]:
        s=i-1
        g=i
        while 1:
            if i>=N or last!=a[i][0]:
                g=i
                break
            i+=1
        for j in reversed(range(s,g)):
            print(a[j][2])
        if i==N-1:
            break
    else:
        print(a[i-1][2])

