N = int(eval(input()))

l = []

for i in range(N):

    s,p = input().split(" ")

    l.append([s,-int(p),i+1])

l.sort()



for s,p,i in l:

    print(i)
N = int(eval(input()))

l = []

for i in range(N):

    s,p = input().split(" ")

    l.append([s,-int(p),i+1])

l.sort()



for i in l:

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

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

-for s, p, i in l: -    print(i) +for i in l: +    print((i[2]))