#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N=2e5+9;

int n,l[N],r[N];
vector<int>x,y;

int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--){
        x.clear();
        y.clear();
        cin>>n;
        for(int i=0;i<n;i++){
            cin>>l[i]>>r[i];
            x.push_back(r[i]);
            y.push_back(l[i]);
        }
        sort(x.begin(),x.end());
        sort(y.begin(),y.end());
        int ans=1e9;
        for(int i=0;i<n;i++){
            int c=y.end()-upper_bound(y.begin(),y.end(),r[i]);
            int c1=lower_bound(x.begin(),x.end(),l[i])-x.begin();
            ans=min(ans,c+c1);
        }
        cout<<ans<<'\n';
    }
}