#include <bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll  long long
#define int long long
#define ld  long double
#define endl "\n"
#define pb  push_back
#define fill(a,val) memset(a,val,sizeof(a))
#define ff  first
#define ss  second
#define test  ll t; cin>>t; while(t--)
#define loop(i,a,b)  for(ll i=a;i<b;i++)
#define loopr(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<ll,ll>
#define all(v) v.begin(),v.end()
const ll mod     = 1000*1000*1000+7;
const ll inf     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll mod2    = 998244353;
const ll N       = 1000 + 10;
const ld pi      = 3.141592653589793;
ll power(ll x,ll y,ll p = LLONG_MAX ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}

void solve(){
    ll n;
    cin>>n;
    pii p[n];
    ll l[n],r[n];
    loop(i,0,n){
        cin>>p[i].ff>>p[i].ss;
        l[i]=p[i].ff;
        r[i]=p[i].ss;
    }
    sort(l,l+n);
    sort(r,r+n);
    ll ans=LLONG_MAX;
    for(ll i=0;i<n;i++){
        ll cnt=0;
        // for(ll j=0;j<n;j++){
        //     if(p[j].ff>r || p[j].ss<l){
        //         continue;
        //     }
        //     cnt++;
        // }
        auto it=upper_bound(l,l+n,p[i].ss)-l;
        cnt+=n-it;
        auto it2=lower_bound(r,r+n,p[i].ff)-r;
        cnt+=it2;
        ans=min(ans,cnt);
    }
    cout<<ans<<endl;
    return;
}
signed main(){
    fastio();
    test{
        
        solve();
        
    }
    return 0;
}