N = int(eval(input()))



ss = dict()

sss = dict()

for i in range(N):

    s, p = input().split()

    sss[s, p] = i + 1

    if s in ss:

        ss[s] = ss[s] + ',' + p

    else:

        ss[s] = p



ss_sorted = sorted(ss.items())



for tmp_ss in ss_sorted:

    s = tmp_ss[0]

    ps = list(map(int, tmp_ss[1].split(',')))

    ps.sort(reverse=True)

    for p in ps:

        print((sss[s, str(p)]))
N = int(eval(input()))





ss = list()

for i in range(N):

    s, p = input().split()

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



ss_sorted = sorted(ss, key=lambda x: (x[0], -x[1]))



for out in ss_sorted:

    print((out[2] + 1))
N = int(eval(input()))
ss = dict()
sss = dict()
for i in range(N):
    s, p = input().split()
    sss[s, p] = i + 1
    if s in ss:
        ss[s] = ss[s] + "," + p
    else:
        ss[s] = p
ss_sorted = sorted(ss.items())
for tmp_ss in ss_sorted:
    s = tmp_ss[0]
    ps = list(map(int, tmp_ss[1].split(",")))
    ps.sort(reverse=True)
    for p in ps:
        print((sss[s, str(p)]))

N = int(eval(input()))
ss = list()
for i in range(N):
    s, p = input().split()
    ss.append([s, int(p), i])
ss_sorted = sorted(ss, key=lambda x: (x[0], -x[1]))
for out in ss_sorted:
    print((out[2] + 1))

-ss = dict() -sss = dict() +ss = list() -    sss[s, p] = i + 1 -    if s in ss: -        ss[s] = ss[s] + "," + p -    else: -        ss[s] = p -ss_sorted = sorted(ss.items()) -for tmp_ss in ss_sorted: -    s = tmp_ss[0] -    ps = list(map(int, tmp_ss[1].split(","))) -    ps.sort(reverse=True) -    for p in ps: -        print((sss[s, str(p)])) +    ss.append([s, int(p), i]) +ss_sorted = sorted(ss, key=lambda x: (x[0], -x[1])) +for out in ss_sorted: +    print((out[2] + 1))