def solveans(dat): last=dat[0][1] ans=L for i in range(1,N): ans+=abs(last-dat[i][1]) ans+=dat[i][-1] return ans from collections import defaultdict import math T=int(input()) for _ in range(T): N,L=map(int,input().split()) dat=defaultdict(list) sl=-(-L//math.sqrt(N)) for _ in range(N): x,y=map(int,input().split()) dat[(y//sl)].append([x,y]) for k in dat.keys(): dat[k].sort() keys=sorted(dat.keys()) ans=[] for k in keys: for d in dat[k]: ans.append(d) print(len(ans)) for a,b in ans: print(a,b)