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**(1/2) LIST=[[] for i in range(int(L**(1/2)+3))] for x,y in P: LIST[int(x/c)].append((x,y)) ANS=[] for i in range(len(LIST)): LIST[i].sort() 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])