n=int(eval(input()))

List=[]

for i in range(n):

    s,p=input().split()

    p=int(p)

    List.append([s,p,i+1])

List.sort()

S=List[0][0]

k=[]

for i in List:

    if i[0]==S:

        k.append([i[1],i[2]])

    else:

        k.sort(reverse=True)

        for j in k:

            print((j[1]))

        S=i[0]

        k=[]

        k.append([i[1],i[2]])

k.sort(reverse=True)

for j in k:

    print((j[1]))

n=int(eval(input()))

List=[]

for i in range(n):

    s,p=input().split()

    p=-int(p)

    List.append([s,p,i+1])

List.sort()

for i in List:

    print((i[2]))

n = int(eval(input()))
List = []
for i in range(n):
    s, p = input().split()
    p = int(p)
    List.append([s, p, i + 1])
List.sort()
S = List[0][0]
k = []
for i in List:
    if i[0] == S:
        k.append([i[1], i[2]])
    else:
        k.sort(reverse=True)
        for j in k:
            print((j[1]))
        S = i[0]
        k = []
        k.append([i[1], i[2]])
k.sort(reverse=True)
for j in k:
    print((j[1]))

n = int(eval(input()))
List = []
for i in range(n):
    s, p = input().split()
    p = -int(p)
    List.append([s, p, i + 1])
List.sort()
for i in List:
    print((i[2]))

-    p = int(p) +    p = -int(p) -S = List[0][0] -k = [] -    if i[0] == S: -        k.append([i[1], i[2]]) -    else: -        k.sort(reverse=True) -        for j in k: -            print((j[1])) -        S = i[0] -        k = [] -        k.append([i[1], i[2]]) -k.sort(reverse=True) -for j in k: -    print((j[1])) +    print((i[2]))