T = int(input()) for _ in range(T): N, L = map(int, input().split()) XY = [list(map(int, input().split())) for _ in range(N)] RANGE = L//N+1 qS = [[] for _ in range(L//RANGE+1)] for i in range(N): X, Y = XY[i] qS[X//RANGE].append((X, Y)) for i in range(L//RANGE+1): qS[i].sort(key=lambda x:x[1], reverse=i%2) ans = [] for q in qS: for x, y in q: ans.append((x, y)) print(len(ans)) for a in ans: print(*a)