from operator import itemgetter



N = int(input())

SP = []

d = {}

for i in range(1, N+1):

    s, p = input().split()

    SP.append([s, -int(p), i])

    d[int(p)] = i

# SP.sort(key= lambda x:x[0])

# SP.sort(key=lambda x:x[1])

SP.sort()

[print(i[2]) for i in SP]

N = int(eval(input()))

SP = []

for i in range(1, N + 1):

    s, p = input().split()

    SP.append((s, int(p), i))

sp = sorted(SP, key=lambda x: x[1], reverse=True)

for i in sorted(sp, key=lambda x: x[0]):

    print((i[2]))

from operator import itemgetter

N = int(input())
SP = []
d = {}
for i in range(1, N + 1):
    s, p = input().split()
    SP.append([s, -int(p), i])
    d[int(p)] = i
# SP.sort(key= lambda x:x[0])
# SP.sort(key=lambda x:x[1])
SP.sort()
[print(i[2]) for i in SP]

N = int(eval(input()))
SP = []
for i in range(1, N + 1):
    s, p = input().split()
    SP.append((s, int(p), i))
sp = sorted(SP, key=lambda x: x[1], reverse=True)
for i in sorted(sp, key=lambda x: x[0]):
    print((i[2]))

-from operator import itemgetter - -N = int(input()) +N = int(eval(input())) -d = {} -    SP.append([s, -int(p), i]) -    d[int(p)] = i -# SP.sort(key= lambda x:x[0]) -# SP.sort(key=lambda x:x[1]) -SP.sort() -[print(i[2]) for i in SP] +    SP.append((s, int(p), i)) +sp = sorted(SP, key=lambda x: x[1], reverse=True) +for i in sorted(sp, key=lambda x: x[0]): +    print((i[2]))