

import math

import itertools

import statistics

#import collections



#n =  list(map(int, input().split()))

n = int(eval(input()))

data = []

for i in range(n):

    s, p = input().split()

    data.append((i+1, s, int(p)))



data.sort(key=lambda x:(x[1], -x[2]))



for i in range(n):

    print((data[i][0]))

n = int(eval(input()))

s = []

for i in range(n):

    x, y = list(input().split())

    s.append([x, int(y), i+1])



ans = sorted(s, key=lambda x: (x[0], -x[1]))

for x, y, a in ans:

    print(a)

import math
import itertools
import statistics

# import collections
# n =  list(map(int, input().split()))
n = int(eval(input()))
data = []
for i in range(n):
    s, p = input().split()
    data.append((i + 1, s, int(p)))
data.sort(key=lambda x: (x[1], -x[2]))
for i in range(n):
    print((data[i][0]))

n = int(eval(input()))
s = []
for i in range(n):
    x, y = list(input().split())
    s.append([x, int(y), i + 1])
ans = sorted(s, key=lambda x: (x[0], -x[1]))
for x, y, a in ans:
    print(a)

-import math -import itertools -import statistics - -# import collections -# n =  list(map(int, input().split())) -data = [] +s = [] -    s, p = input().split() -    data.append((i + 1, s, int(p))) -data.sort(key=lambda x: (x[1], -x[2])) -for i in range(n): -    print((data[i][0])) +    x, y = list(input().split()) +    s.append([x, int(y), i + 1]) +ans = sorted(s, key=lambda x: (x[0], -x[1])) +for x, y, a in ans: +    print(a)