n = int(eval(input()))

dat = []

for i in range(n):

    s,p = input().split()

    p = int(p)

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

res = sorted(dat, key=lambda x: (x[0], -x[1]))

for i in range(len(res)):

    print((res[i][2]))
n = int(eval(input()))

dat = []

for i in range(n):

    s,p = input().split()

    dat.append((s, int(p), i+1))

res = sorted(dat, key=lambda x: (x[0], -x[1]))

for i in range(len(res)):

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

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

-    p = int(p) -    dat.append((s, p, i + 1)) +    dat.append((s, int(p), i + 1))