n = int(input()) books = [] for i in range(n): s, id = input().split() books.append([s, id]) books.sort() for s, id in books: print(s, id)