import sys testCase = int(input()) li = [] for _ in range(testCase): x ,y = map(int, sys.stdin.readline().split()) li.append([y,x]) s_li = sorted(li) for y,x in s_li: print(x,y)