n = int(eval(input()))

city = []

nums = []

result = []



for i in range(n):

  s,p = input().split()

  p = int(p)

  city.append(s)

  nums.append(p)

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



for i in sorted(set(city)):

  for j in sorted(set(nums), reverse = True):

    for k in result:

      if k[0] == i and k[1] == j:

        print((k[2]))
n = int(eval(input()))

l = []

d = {}

for i in range(n):

  s,p = input().split()

  if s not in l:

    l.append(s)

    d[s] = []

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



for i in sorted(l):

  for j in sorted(d[i], reverse=True):

    print((j[1]))
n = int(eval(input()))
city = []
nums = []
result = []
for i in range(n):
    s, p = input().split()
    p = int(p)
    city.append(s)
    nums.append(p)
    result.append([s, p, i + 1])
for i in sorted(set(city)):
    for j in sorted(set(nums), reverse=True):
        for k in result:
            if k[0] == i and k[1] == j:
                print((k[2]))

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

-city = [] -nums = [] -result = [] +l = [] +d = {} -    p = int(p) -    city.append(s) -    nums.append(p) -    result.append([s, p, i + 1]) -for i in sorted(set(city)): -    for j in sorted(set(nums), reverse=True): -        for k in result: -            if k[0] == i and k[1] == j: -                print((k[2])) +    if s not in l: +        l.append(s) +        d[s] = [] +    d[s].append([int(p), i + 1]) +for i in sorted(l): +    for j in sorted(d[i], reverse=True): +        print((j[1]))