#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(a) a.begin(),a.end()

int main()
{  
  ll t=1,n,i,j,m,k,q;
  cin>>t;
  for(q=1;q<=t;q++){
     cin>>n;
     vector<ll> le(n), ri(n), Le(n), Ri(n);
     for(i=0;i<n;i++){
         cin>>Le[i]>>Ri[i];
     }
     le = Le; ri = Ri;
     sort(all(le));
     sort(all(ri));
     ll ans=0;
     for(i=0;i<n;i++){
         ll lower = lower_bound(ri.begin(), ri.end(), Le[i])-ri.begin();
         ll upper = upper_bound(le.begin(), le.end(), Ri[i])-le.begin();
         
         ans = max(ans,upper-lower);
        //  cout<<"lb="<<lower<<" "<<"ub="<<upper<<" "<<"ans="<<ans<<endl;
     }
     cout<<n-ans<<endl;
  }
}