n=int(eval(input()))

d=list(list(input().split())+[i+1] for i in range(n))

d.sort(key=lambda x:(x[0],-int(x[1])))

for v in d:print((v[2]))
n=int(eval(input()))

d=sorted(list(list(input().split())+[i+1] for i in range(n)),key=lambda x:(x[0],-int(x[1])))

for v in d:print((v[2]))
n = int(eval(input()))
d = list(list(input().split()) + [i + 1] for i in range(n))
d.sort(key=lambda x: (x[0], -int(x[1])))
for v in d:
    print((v[2]))

n = int(eval(input()))
d = sorted(
    list(list(input().split()) + [i + 1] for i in range(n)),
    key=lambda x: (x[0], -int(x[1])),
)
for v in d:
    print((v[2]))

-d = list(list(input().split()) + [i + 1] for i in range(n)) -d.sort(key=lambda x: (x[0], -int(x[1]))) +d = sorted( +    list(list(input().split()) + [i + 1] for i in range(n)), +    key=lambda x: (x[0], -int(x[1])), +)