def main():

    N = int(input())
    if 0 > N or N > 100:
        print("input N error")
        exit()
        
    a = []
    for i in range(N):
        b = input().split()
        if len(b[0]) > 10 or len(b[0]) < 1:
            print("input S error")
            exit()

        if int(b[1]) < 0 or int(b[1]) > 100:
            print("input P error")
            exit()

        b.append(i + 1)
        a.append(b)
        
    a.sort()
    c = []
    answer = []
    
    for i in range(len(a) - 1):
        c.append(a[i])

        if i == len(a) - 2:
            elif a[i][0] != a[i+1][0]:
                c.sort(key=lambda x: int(x[1]), reverse=True)
                answer += c
                answer.append(a[i+1])

            else:
                c.append(a[i+1])
                c.sort(key=lambda x: int(x[1]), reverse=True)
                answer += c
                
        elif a[i][0] != a[i+1][0]:
            c.sort(key=lambda x: int(x[1]), reverse=True)
            answer += c
            c = []

            
    for i in range(len(answer)):
        print(answer[i][2])
        
        
if __name__ == '__main__':

    main()

    
