n = int(eval(input()))



ss = []

ps = []

sps = []



for i in range(n):

    temp = input().split()

    ss.append(temp[0])

    ps.append(temp[1])

    sps.append(temp[0] + ' ' + temp[1] + ' ' + str(i))



def check(sps):

    city = sps[0].split()[0]

    score = int(sps[0].split()[1])

#    score = sps[0].split()[1]

    index = int(sps[0].split()[2])

    target = 0





    for i in range(1, len(sps)):

#        print(sps[i].split()[1])

#        print(score)



        if sps[i].split()[0] == city and score < int(sps[i].split()[1]):

#        if sps[i].split()[0] == city and score < sps[i].split()[1]:

            city = sps[i].split()[0]

            score = int(sps[i].split()[1])

            index = int(sps[i].split()[2])

            target = i

        elif sps[i].split()[0] < city:

            city = sps[i].split()[0]

            score = int(sps[i].split()[1])

            index = int(sps[i].split()[2])

            target = i



    # print(index + 1)

    # del sps[i]

#    return index

    return target, index



for i in range(n):

    target, index = check(sps)

    print((index + 1))

    del sps[target]

n = int(eval(input()))

sps = []



for i in range(n):

    line = input().split()

    sps.append([line[0], -(int(line[1])), i + 1])



sps.sort()



for i in range(n):

    print((sps[i][2]))

n = int(eval(input()))
ss = []
ps = []
sps = []
for i in range(n):
    temp = input().split()
    ss.append(temp[0])
    ps.append(temp[1])
    sps.append(temp[0] + " " + temp[1] + " " + str(i))


def check(sps):
    city = sps[0].split()[0]
    score = int(sps[0].split()[1])
    #    score = sps[0].split()[1]
    index = int(sps[0].split()[2])
    target = 0
    for i in range(1, len(sps)):
        #        print(sps[i].split()[1])
        #        print(score)
        if sps[i].split()[0] == city and score < int(sps[i].split()[1]):
            #        if sps[i].split()[0] == city and score < sps[i].split()[1]:
            city = sps[i].split()[0]
            score = int(sps[i].split()[1])
            index = int(sps[i].split()[2])
            target = i
        elif sps[i].split()[0] < city:
            city = sps[i].split()[0]
            score = int(sps[i].split()[1])
            index = int(sps[i].split()[2])
            target = i
    # print(index + 1)
    # del sps[i]
    #    return index
    return target, index


for i in range(n):
    target, index = check(sps)
    print((index + 1))
    del sps[target]

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

-ss = [] -ps = [] -    temp = input().split() -    ss.append(temp[0]) -    ps.append(temp[1]) -    sps.append(temp[0] + " " + temp[1] + " " + str(i)) - - -def check(sps): -    city = sps[0].split()[0] -    score = int(sps[0].split()[1]) -    #    score = sps[0].split()[1] -    index = int(sps[0].split()[2]) -    target = 0 -    for i in range(1, len(sps)): -        #        print(sps[i].split()[1]) -        #        print(score) -        if sps[i].split()[0] == city and score < int(sps[i].split()[1]): -            #        if sps[i].split()[0] == city and score < sps[i].split()[1]: -            city = sps[i].split()[0] -            score = int(sps[i].split()[1]) -            index = int(sps[i].split()[2]) -            target = i -        elif sps[i].split()[0] < city: -            city = sps[i].split()[0] -            score = int(sps[i].split()[1]) -            index = int(sps[i].split()[2]) -            target = i -    # print(index + 1) -    # del sps[i] -    #    return index -    return target, index - - +    line = input().split() +    sps.append([line[0], -(int(line[1])), i + 1]) +sps.sort() -    target, index = check(sps) -    print((index + 1)) -    del sps[target] +    print((sps[i][2]))