n = int(eval(input()))



l = []

ans = []



for i in range(1, n+1):

    s, p = input().split()

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



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

for j in ans:

    print((j[2]))
n = int(eval(input()))



l = []



for i in range(1, n+1):

    s, p = input().split()

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



l = sorted(l, key=lambda x: x[1],reverse=True)

l = sorted(l, key=lambda x: x[0])       



for j in l:

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

n = int(eval(input()))
l = []
for i in range(1, n + 1):
    s, p = input().split()
    l.append([s, int(p), i])
l = sorted(l, key=lambda x: x[1], reverse=True)
l = sorted(l, key=lambda x: x[0])
for j in l:
    print((j[2]))

-ans = [] -ans = sorted(l, key=lambda x: (x[0], -x[1])) -for j in ans: +l = sorted(l, key=lambda x: x[1], reverse=True) +l = sorted(l, key=lambda x: x[0]) +for j in l: