Case = int(input())

customer_list = []
for i in range(Case):
    age, name = input().split()
    age = int(age)
    customer_list.append([age, name, i])
customer_list = sorted(customer_list, key = lambda x : (x[0], x[2]))
sorted_customer_list = list(map(lambda x : x[:-1], customer_list))
for customer in sorted_customer_list:
    print(*customer)