n = int(input())
points = []
for _ in range(n):
x, y = map(int, input().split())
points.append((x, y))
sorted_points = sorted(points, key=lambda point: (point[1], point[0]))
for point in sorted_points:
print(point[0], point[1])
위 포스팅 참고, 정렬 기준을 변경 x -> y 에서 y -> x 로 변경하면 된다.