Q=int(input()) for _ in range(Q): N,L=map(int,input().split()) k=L//300+1 G=[[] for i in range(300)] for i in range(N): x,y=map(int,input().split()) pos=x//k G[pos].append((y,x)) for i in range(300): G[i].sort() result=[] for i in range(300): for B in G[i]: y,x=B[:] result.append((x,y)) print(len(result)) for i in range(len(result)): x,y=result[i][:] print(x,y)