#include<bits/stdc++.h>
#define fori(i,n) for(int i=0;i<n;++i)
#define pii pair<int,int> 
#define ti tuple<int, int, int>
#define ll long long

const int mod=1e9+7;

using namespace std;
const int maxn=1e6;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int test=1;
    cin>>test;
    fori(t, test){
        int n;
        cin>>n;
        vector<int> l(n), r(n);
        fori(i,n) cin>>l[i]>>r[i];
        int l2[n], r2[n];
        fori(i,n) l2[i]=l[i], r2[i]=r[i];
        sort(l.begin(), l.end());
        sort(r.begin(), r.end());
        int mini=INT_MAX;
        fori(i,n){
            int ct=lower_bound(r.begin(), r.end(), l2[i])-r.begin();
            int ct2=l.end()-upper_bound(l.begin(), l.end(), r2[i]);
            //cout<<ct<<" "<<ct2;
            if(mini>ct+ct2) mini=ct+ct2;
        }
        cout<<mini<<'\n';

    }



    return 0;
}