import sys input = sys.stdin.readline T = int(input()) for _ in range(T): N, L = map(int, input().split()) XY = [list(map(int, input().split())) for _ in range(N)] for i in range(N): x, y = XY[i] XY[i] = [x, y, x+y] XY.sort(key=lambda x:x[2]) ans = [] for x, y, _ in XY: ans.append((x, y)) print(len(ans)) for a in ans: print(*a)