import copy



n = int(eval(input()))

l = [input().split() for i in range(n)]

index = copy.deepcopy(l)



for i in range(n):

    l[i][1] = int(l[i][1])

    index[i][1] = int(index[i][1])



l.sort(key=lambda x: x[1], reverse=True)

l.sort(key=lambda x: x[0], reverse=False)



for i in range(n):

    for j in range(n):

        if l[i] == index[j]:

            print((j+1))

            break

import copy



res_list = []

n = int(eval(input()))

for i in range(n):

    name, score = input().split()

    score = int(score)



    res_list.append([name,score,i+1])



res_list.sort(key=lambda x: x[1],reverse=True)

res_list.sort(key=lambda x: x[0],reverse=False)



for i in res_list:

    print((i[2]))



import copy

n = int(eval(input()))
l = [input().split() for i in range(n)]
index = copy.deepcopy(l)
for i in range(n):
    l[i][1] = int(l[i][1])
    index[i][1] = int(index[i][1])
l.sort(key=lambda x: x[1], reverse=True)
l.sort(key=lambda x: x[0], reverse=False)
for i in range(n):
    for j in range(n):
        if l[i] == index[j]:
            print((j + 1))
            break

import copy

res_list = []
n = int(eval(input()))
for i in range(n):
    name, score = input().split()
    score = int(score)
    res_list.append([name, score, i + 1])
res_list.sort(key=lambda x: x[1], reverse=True)
res_list.sort(key=lambda x: x[0], reverse=False)
for i in res_list:
    print((i[2]))

+res_list = [] -l = [input().split() for i in range(n)] -index = copy.deepcopy(l) -    l[i][1] = int(l[i][1]) -    index[i][1] = int(index[i][1]) -l.sort(key=lambda x: x[1], reverse=True) -l.sort(key=lambda x: x[0], reverse=False) -for i in range(n): -    for j in range(n): -        if l[i] == index[j]: -            print((j + 1)) -            break +    name, score = input().split() +    score = int(score) +    res_list.append([name, score, i + 1]) +res_list.sort(key=lambda x: x[1], reverse=True) +res_list.sort(key=lambda x: x[0], reverse=False) +for i in res_list: +    print((i[2]))