N = int(eval(input()))

sp = [list(input().split()) for i in range(N)]

for i in range(N):

  sp[i].append(i+1)

sorted_data = sorted(sp, key=lambda x:(x[0], -int(x[1])))

for i in range(N):

  print((sorted_data[i][2]))
N = int(eval(input()))

D = [list(map(str,input().split())) for _ in range(N)]

for i in range(N):

  D[i].append(i+1)

sorted_d = sorted(D, key = lambda x: (x[0], -int(x[1])))

for i in range(N):

  print((sorted_d[i][2]))
N = int(eval(input()))
sp = [list(input().split()) for i in range(N)]
for i in range(N):
    sp[i].append(i + 1)
sorted_data = sorted(sp, key=lambda x: (x[0], -int(x[1])))
for i in range(N):
    print((sorted_data[i][2]))

N = int(eval(input()))
D = [list(map(str, input().split())) for _ in range(N)]
for i in range(N):
    D[i].append(i + 1)
sorted_d = sorted(D, key=lambda x: (x[0], -int(x[1])))
for i in range(N):
    print((sorted_d[i][2]))

-sp = [list(input().split()) for i in range(N)] +D = [list(map(str, input().split())) for _ in range(N)] -    sp[i].append(i + 1) -sorted_data = sorted(sp, key=lambda x: (x[0], -int(x[1]))) +    D[i].append(i + 1) +sorted_d = sorted(D, key=lambda x: (x[0], -int(x[1]))) -    print((sorted_data[i][2])) +    print((sorted_d[i][2]))