#include #include #include #include #include using namespace std; void solve (int N, int L, vector>& points) { // 最適解は求められないはず -> Moの巡回順でやってみる int width = (int) (L / sqrt(N)); vector> query(N); for (int i = 0; i < N; i++) { query[i] = make_tuple(points[i].first, points[i].second, points[i].first / width); } sort(query.begin(), query.end(), [](tuple& x, tuple& y) { if (get<2>(x) != get<2>(y)) return get<2>(x) < get<2>(y); return get<1>(x) < get<1>(y); }); cout << N << "\n"; for (auto& q : query) { cout << get<0>(q) << " " << get<1>(q) << "\n"; } } int main () { int T; cin >> T; for (int t = 0; t < T; t++) { int N, L; cin >> N >> L; vector> points(N); for (int i = 0; i < N; i++) { int X, Y; cin >> X >> Y; points[i] = make_pair(X, Y); } solve(N, L, points); } }