n = int(eval(input()))

l = [0] * n

for i in range(n):

    l[i] = input().split()

#l.sort(key=lambda x: x[0]

s = sorted(list(set([l[i][0] for i in range(n)])))

for q in s:

    p = sorted([int(l[i][1]) for i in range(n) if l[i][0] == q], reverse=1)

    for pp in p:

        ans = l.index([q,str(pp)]) + 1

        print(ans)

n = int(eval(input()))

l = []

for i in range(n):

    s, p = input().split()

    l.append((s,-int(p),i))



print(('\n'.join([str(t[2]+1) for t in sorted(l)])))

n = int(eval(input()))
l = [0] * n
for i in range(n):
    l[i] = input().split()
# l.sort(key=lambda x: x[0]
s = sorted(list(set([l[i][0] for i in range(n)])))
for q in s:
    p = sorted([int(l[i][1]) for i in range(n) if l[i][0] == q], reverse=1)
    for pp in p:
        ans = l.index([q, str(pp)]) + 1
        print(ans)

n = int(eval(input()))
l = []
for i in range(n):
    s, p = input().split()
    l.append((s, -int(p), i))
print(("\n".join([str(t[2] + 1) for t in sorted(l)])))

-l = [0] * n +l = [] -    l[i] = input().split() -# l.sort(key=lambda x: x[0] -s = sorted(list(set([l[i][0] for i in range(n)]))) -for q in s: -    p = sorted([int(l[i][1]) for i in range(n) if l[i][0] == q], reverse=1) -    for pp in p: -        ans = l.index([q, str(pp)]) + 1 -        print(ans) +    s, p = input().split() +    l.append((s, -int(p), i)) +print(("\n".join([str(t[2] + 1) for t in sorted(l)])))