n = int(input())
stu = []
for i in range(n):
    a, b = map(int, input().split(" "))
    stu.append((a, b))
stu.sort(key=lambda x: (x[1], x[0]))#sort内置是可以用元组排序的
for x in stu:
    print(x[0], end=" ")
    print(x[1])