#pragma GCC optimize ("O2")
#include <bits/stdc++.h>
#define fr(i,a,b) for (int i = a; i<=b;i++)
#define frd(i,a,b) for (int i = a; i>=b;i--)
using namespace std;
typedef long long ll;
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int t; cin >> t; while(t--){
        int n; cin >> n;
        int l[n],r[n],a[n],b[n],e[n],f[n];
        fr(i,0,n-1){
            cin >> l[i]>>r[i];
            a[i]=l[i];
            b[i]=r[i];
        }
        sort(a,a+n); sort(b,b+n);
        int curr=-1;
        fr(i,0,n-1){
            fr(j,curr+1,n-1){
                if (b[j]>=a[i]) break;
                curr=j;
            }
            e[i]=curr+1;
        }
        curr=-1;
        fr(i,0,n-1){
            fr(j,curr+1,n-1){
                if (a[j]>b[i]) break;
                curr=j;
            }
            f[i]=n-curr-1;
        }
        int res=1e8;
        fr(i,0,n-1){
            int r1 = lower_bound(a,a+n,l[i])-a;
            int r2=lower_bound(b,b+n,r[i])-b;
            res=min(res,e[r1]+f[r2]);
        }
        cout << res<<'\n';
    }

}
