N = int(eval(input()))



xy = []

for i in range(N):

    x, y = list(map(str, input().split()))

    y = int(y)

    xy.append([x, y])



sort_xy = sorted(sorted(xy), key=lambda x: (x[0],-x[1]))



for i in range(N):

    for j in range(N):

        if sort_xy[i][0] == xy[j][0]:

            if sort_xy[i][1] == xy[j][1]:

                print((j + 1))
N = int(eval(input()))



xy = []

for i in range(N):

    x, y = input().split()

    xy.append([i + 1, x, int(y)])



sort_xy = sorted(sorted(xy), key=lambda x: (x[1],-x[2]))



for i in range(N):

    print((sort_xy[i][0]))

N = int(eval(input()))
xy = []
for i in range(N):
    x, y = list(map(str, input().split()))
    y = int(y)
    xy.append([x, y])
sort_xy = sorted(sorted(xy), key=lambda x: (x[0], -x[1]))
for i in range(N):
    for j in range(N):
        if sort_xy[i][0] == xy[j][0]:
            if sort_xy[i][1] == xy[j][1]:
                print((j + 1))

N = int(eval(input()))
xy = []
for i in range(N):
    x, y = input().split()
    xy.append([i + 1, x, int(y)])
sort_xy = sorted(sorted(xy), key=lambda x: (x[1], -x[2]))
for i in range(N):
    print((sort_xy[i][0]))

-    x, y = list(map(str, input().split())) -    y = int(y) -    xy.append([x, y]) -sort_xy = sorted(sorted(xy), key=lambda x: (x[0], -x[1])) +    x, y = input().split() +    xy.append([i + 1, x, int(y)]) +sort_xy = sorted(sorted(xy), key=lambda x: (x[1], -x[2])) -    for j in range(N): -        if sort_xy[i][0] == xy[j][0]: -            if sort_xy[i][1] == xy[j][1]: -                print((j + 1)) +    print((sort_xy[i][0]))