n = int(eval(input()))

X = []

for i in range(n):

    s, p = list(map(str, input().split()))

    p = int(p)

    X.append((s, p, i+1))



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

for s, p, i in X:

    print(i)

n = int(eval(input()))

SP = []

for i in range(n):

    s, p = list(map(str, input().split()))

    p = int(p)

    SP.append((s, p, i+1))

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

for s, p, j in SP:

    print(j)

n = int(eval(input()))
X = []
for i in range(n):
    s, p = list(map(str, input().split()))
    p = int(p)
    X.append((s, p, i + 1))
X.sort(key=lambda x: (x[0], -x[1]))
for s, p, i in X:
    print(i)

n = int(eval(input()))
SP = []
for i in range(n):
    s, p = list(map(str, input().split()))
    p = int(p)
    SP.append((s, p, i + 1))
SP.sort(key=lambda x: (x[0], -x[1]))
for s, p, j in SP:
    print(j)

-X = [] +SP = [] -    X.append((s, p, i + 1)) -X.sort(key=lambda x: (x[0], -x[1])) -for s, p, i in X: -    print(i) +    SP.append((s, p, i + 1)) +SP.sort(key=lambda x: (x[0], -x[1])) +for s, p, j in SP: +    print(j)