#include using namespace std; using ll = long long; int N, L; int X[201010], Y[201010], ord[201010]; void solve(){ cin >> N >> L; for(int i = 0;i < N;i++)cin >> X[i] >> Y[i]; for(int i = 0;i < N;i++)ord[i] = i; int B = L / sqrt(N); B = max(1, B); sort(ord, ord + N, [&B](int a, int b){ if(X[a] / B == Y[a] / B){ return Y[a] < Y[b]; } return X[a] / B < Y[a] / B; }); cout << N << endl; for(int i = 0;i < N;i++){ cout << X[ord[i]] << " " << Y[ord[i]] << " \n"; } } int main(void){ ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while(t--)solve(); return 0; }