n=int(eval(input()))

c,m=[],[]

d={}

t={}

for i in range(n):

    s,p=list(map(str,input().split()))

    m.append((s,int(p)))

    if s not in c:

        c.append(s)

        d[s]=[int(p)]

    else:

        d[s].append(int(p))

    t[(s,int(p))]=i+1

c.sort()

ans={}

cnt=1

for i in c:

    d[i].sort(reverse=True)

    for j in d[i]:

        ans[cnt]=(i,j)

        cnt+=1

for i in range(1,n+1):

    print((t[ans[i]]))

n=int(eval(input()))

ans=[]

for i in range(n):

    s,p=list(map(str,input().split()))

    ans.append((s,int(p)*-1,i+1))

ans.sort()

for i in ans: print((i[2]))
n = int(eval(input()))
c, m = [], []
d = {}
t = {}
for i in range(n):
    s, p = list(map(str, input().split()))
    m.append((s, int(p)))
    if s not in c:
        c.append(s)
        d[s] = [int(p)]
    else:
        d[s].append(int(p))
    t[(s, int(p))] = i + 1
c.sort()
ans = {}
cnt = 1
for i in c:
    d[i].sort(reverse=True)
    for j in d[i]:
        ans[cnt] = (i, j)
        cnt += 1
for i in range(1, n + 1):
    print((t[ans[i]]))

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

-c, m = [], [] -d = {} -t = {} +ans = [] -    m.append((s, int(p))) -    if s not in c: -        c.append(s) -        d[s] = [int(p)] -    else: -        d[s].append(int(p)) -    t[(s, int(p))] = i + 1 -c.sort() -ans = {} -cnt = 1 -for i in c: -    d[i].sort(reverse=True) -    for j in d[i]: -        ans[cnt] = (i, j) -        cnt += 1 -for i in range(1, n + 1): -    print((t[ans[i]])) +    ans.append((s, int(p) * -1, i + 1)) +ans.sort() +for i in ans: +    print((i[2]))