N = int(input()) b = [] for i in range(N): s, t = map(str, input().split()) b.append((s, t)) b.sort() for c in b: print(*c)