n = int(eval(input()))

sp = [input().split() for _ in range(n)]

for i in sorted(list(range(n)), key=lambda i: (sp[i][0], -int(sp[i][1]))):

    print((i + 1))
n = int(eval(input()))

sp = [input().split() for _ in range(n)]

for (s, p), i in sorted(zip(sp, list(range(1, n + 1))), key=lambda x: (x[0][0], -int(x[0][1]))):

    print(i)
n = int(eval(input()))
sp = [input().split() for _ in range(n)]
for i in sorted(list(range(n)), key=lambda i: (sp[i][0], -int(sp[i][1]))):
    print((i + 1))

n = int(eval(input()))
sp = [input().split() for _ in range(n)]
for (s, p), i in sorted(
    zip(sp, list(range(1, n + 1))), key=lambda x: (x[0][0], -int(x[0][1]))
):
    print(i)

-for i in sorted(list(range(n)), key=lambda i: (sp[i][0], -int(sp[i][1]))): -    print((i + 1)) +for (s, p), i in sorted( +    zip(sp, list(range(1, n + 1))), key=lambda x: (x[0][0], -int(x[0][1])) +): +    print(i)