#include #pragma GCC optimize("unroll-loops") using namespace std; using std::cout; using std::cin; using std::endl; using ll=long long; using ld=long double; const ll ILL=2167167167167167167; const int INF=2100000000; const int mod=998244353; #define rep(i,a,b) for (int i=(int)(a);i<(int)(b);i++) #define all(p) p.begin(),p.end() template using _pq = priority_queue, greater>; template ll LB(vector &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();} template ll UB(vector &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();} template bool chmin(T &a,T b){if(a>b){a=b;return 1;}else return 0;} template bool chmax(T &a,T b){if(a void So(vector &v) {sort(v.begin(),v.end());} template void Sore(vector &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});} void yneos(bool a,bool upp=0){if(a) cout<<(upp?"YES\n":"Yes\n"); else cout<<(upp?"NO\n":"No\n");} template void vec_out(vector &p,int ty=0){ if(ty==2){cout<<'{';for(int i=0;i<(int)p.size();i++){if(i){cout<<",";}cout<<'"'< T vec_min(vector &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmin(ans,x);return ans;} template T vec_max(vector &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmax(ans,x);return ans;} template T vec_sum(vector &a){T ans=T(0);for(auto &x:a) ans+=x;return ans;} int pop_count(long long a){int res=0;while(a){res+=(a&1),a>>=1;}return res;} namespace po167{ struct Mo{ std::vector left,right,order; int width,nl,nr,index,_n; Mo(int n):width((int) std::sqrt(n)),nl(0),nr(0),index(0),_n(0){} //[l,r) void insert(int l,int r){ //assert(l<=r); left.push_back(l); right.push_back(r); } void bulid(){ //width=(int)((double)_n/std::max((double)1,sqrt((int)(left.size())))); width=max(1,width); order.resize((int)left.size()); std::vector order1((int)left.size()); std::iota(order1.begin(),order1.end(),0); auto order2=order1; std::sort(order1.begin(),order1.end(),[&](int a,int b){ if(left[a]/width!=left[b]/width){ return left[a]>left[b]; } else if((left[a]/width)&1){ return right[a]right[b]; }); std::sort(order2.begin(),order2.end(),[&](int a,int b){ if((width/2+left[a])/width!=(width/2+left[b])/width){ return left[a]>left[b]; } else if(((width/2+left[a])/width)&1){ return right[a]right[b]; }); ll score1=0,score2=0; for(int i=1;i<(int)(left.size());i++){ score1+=std::abs(left[order1[i]]-left[order1[i-1]]); score1+=std::abs(right[order1[i]]-right[order1[i-1]]); score2+=std::abs(left[order2[i]]-left[order2[i-1]]); score2+=std::abs(right[order2[i]]-right[order2[i-1]]); } if(score1left[now]) nl--,add(nl); //while(nlright[now]) nr--,del(nr); index++; return now; } }; } using po167::Mo; void solve(); // oddloop int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t=1; cin>>t; rep(i,0,t) solve(); } void solve(){ int N,L; cin>>N>>L; Mo X(L); vector A(N),B(N); rep(i,0,N){ int a,b; cin>>a>>b; A[i]=a,B[i]=b; X.insert(a,b); } X.bulid(); cout<