N = int(eval(input()))



S = [""] * N

P = [0] * N



for i in range(N):

    S[i], P[i] = input().split()

    P[i] = int(P[i])





new_S = sorted(S)



same_v = []

same_i = []

for i, name in enumerate(new_S):

    for k in range(N):

        if new_S[i] == S[k]:

            same_v.append(P[k])

            same_i.append(k)

    x = same_i[same_v.index(max(same_v))]

    print((x + 1))

    same_v = []

    same_i = []

    P[x] = -1
N = int(eval(input()))



SP = []

for i in range(N):

    s, p = input().split()

    SP.append([s] + [int(p)] + [i + 1])



new_SP = sorted(SP, key=lambda x: (x[0], -x[1]))



for _, _, i in new_SP:

    print(i)
N = int(eval(input()))
S = [""] * N
P = [0] * N
for i in range(N):
    S[i], P[i] = input().split()
    P[i] = int(P[i])
new_S = sorted(S)
same_v = []
same_i = []
for i, name in enumerate(new_S):
    for k in range(N):
        if new_S[i] == S[k]:
            same_v.append(P[k])
            same_i.append(k)
    x = same_i[same_v.index(max(same_v))]
    print((x + 1))
    same_v = []
    same_i = []
    P[x] = -1

N = int(eval(input()))
SP = []
for i in range(N):
    s, p = input().split()
    SP.append([s] + [int(p)] + [i + 1])
new_SP = sorted(SP, key=lambda x: (x[0], -x[1]))
for _, _, i in new_SP:
    print(i)

-S = [""] * N -P = [0] * N +SP = [] -    S[i], P[i] = input().split() -    P[i] = int(P[i]) -new_S = sorted(S) -same_v = [] -same_i = [] -for i, name in enumerate(new_S): -    for k in range(N): -        if new_S[i] == S[k]: -            same_v.append(P[k]) -            same_i.append(k) -    x = same_i[same_v.index(max(same_v))] -    print((x + 1)) -    same_v = [] -    same_i = [] -    P[x] = -1 +    s, p = input().split() +    SP.append([s] + [int(p)] + [i + 1]) +new_SP = sorted(SP, key=lambda x: (x[0], -x[1])) +for _, _, i in new_SP: +    print(i)