n = int(input())
S = []
count = [0] * n
for i in range(n):
    a, b = input().split()
    S.append([a, int(b), i + 1])

S.sort()

for i in range(n - 1):
    if S[i][0] != S[i + 1][0]:
        count[i] = 1

for j in range(n-1):
    for i in range(n - 1):
        if S[i][1] < S[i + 1][1] and count[i + 1] - count[i] >= 0:
            a = S[i][:]
            S[i][:] = S[i + 1][:]
            S[i + 1][:] = a
        if count[i + 1] - count[i] < 0:
            continue

for i in range(n):
    print(S[i][2])


