n = int(eval(input()))

d = {}

for i in range(n):

    s ,p = input().split()

    p = int(p)

    if not(s in d):

        d[s] = {}

    d[s][p*-1] = i+1

for i in sorted(d.keys()):

    for j in sorted(d[i].keys()):

        print((d[i][j]))

n = int(eval(input()))

s = []

p = [0] * 101

d = {}

for i in range(n):

    a,b = input().split()

    b = int(b)

    s.append(a)

    p[b] = i+1

    if a in list(d.keys()):

        d[a].append(b)

        continue

    d[a] = [b]

s = sorted(set(s))

for i in s:

    c = sorted(d[i],reverse=True)

    for j in c:

        print((p[j]))

n = int(eval(input()))
d = {}
for i in range(n):
    s, p = input().split()
    p = int(p)
    if not (s in d):
        d[s] = {}
    d[s][p * -1] = i + 1
for i in sorted(d.keys()):
    for j in sorted(d[i].keys()):
        print((d[i][j]))

n = int(eval(input()))
s = []
p = [0] * 101
d = {}
for i in range(n):
    a, b = input().split()
    b = int(b)
    s.append(a)
    p[b] = i + 1
    if a in list(d.keys()):
        d[a].append(b)
        continue
    d[a] = [b]
s = sorted(set(s))
for i in s:
    c = sorted(d[i], reverse=True)
    for j in c:
        print((p[j]))

+s = [] +p = [0] * 101 -    s, p = input().split() -    p = int(p) -    if not (s in d): -        d[s] = {} -    d[s][p * -1] = i + 1 -for i in sorted(d.keys()): -    for j in sorted(d[i].keys()): -        print((d[i][j])) +    a, b = input().split() +    b = int(b) +    s.append(a) +    p[b] = i + 1 +    if a in list(d.keys()): +        d[a].append(b) +        continue +    d[a] = [b] +s = sorted(set(s)) +for i in s: +    c = sorted(d[i], reverse=True) +    for j in c: +        print((p[j]))