import sys input = sys.stdin.readline T=int(input()) for tests in range(T): N,L=map(int,input().split()) P=[list(map(int,input().split())) for i in range(N)] c=L/(N**(1/2)) LIST=[[] for i in range(int(L/c+3))] for x,y in P: LIST[int(x/c)].append((x,y)) ANS=[] for i in range(len(LIST)): LIST[i].sort() if i%2==1: LIST[i].reverse() for x,y in LIST[i]: ANS.append((x,y)) print(len(ANS)+1) for x,y in ANS: print(x,y) print(*ANS[0])