n = int(eval(input()))

SP = []

for i in range(n):

    s, p = input().split()

    SP += [[s,int(p),i+1]]

SP.sort(key=lambda A:(A[0],-A[1]))

for sp in SP:

	print((sp[2]))
N = int(eval(input()))



SP = []

for i in range(N):

  s,p = input().split()

  SP.append((s,-int(p),i+1))

  

SP.sort()



for s,p,i in SP:

  print(i)
n = int(eval(input()))
SP = []
for i in range(n):
    s, p = input().split()
    SP += [[s, int(p), i + 1]]
SP.sort(key=lambda A: (A[0], -A[1]))
for sp in SP:
    print((sp[2]))

N = int(eval(input()))
SP = []
for i in range(N):
    s, p = input().split()
    SP.append((s, -int(p), i + 1))
SP.sort()
for s, p, i in SP:
    print(i)

-n = int(eval(input())) +N = int(eval(input())) -for i in range(n): +for i in range(N): -    SP += [[s, int(p), i + 1]] -SP.sort(key=lambda A: (A[0], -A[1])) -for sp in SP: -    print((sp[2])) +    SP.append((s, -int(p), i + 1)) +SP.sort() +for s, p, i in SP: +    print(i)