#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define en cin.close();return 0;
#define INF ((ll)(4e18))
#define pb push_back
#define fi first//printf("%lli\n",cur);
#define se second//scanf("%lli",&n);
using namespace std;
int main()
{
    fio
    //ifstream cin("in.inn");
    ll qq;
    cin >> qq;
    while(qq--)
    {
        ll n, res = INF;
        cin >> n;
        pair<ll,ll> p[n];
        ll l[n], r[n];
        for(ll i = 0;i<n;i++)
        {
            ll a, b;
            cin >> a >> b;
            p[i]={a,b};
            l[i]=a;
            r[i]=b;
        }
        sort(l,l+n);
        sort(r,r+n);
        for(auto i:p)
        {
            ll a = i.fi , b = i.se, bad = 0;
            ll l1 = 0, r1 = n-1;
            while(l1<r1)
            {
                ll mid = (l1+r1)/2;
                if(l[mid]<=b)
                    l1=mid+1;
                else
                    r1=mid;
            }
            if(l[l1]>b)
                bad+=n-l1;
            l1 = 0, r1 = n-1;
            while(l1<r1)
            {
                ll mid = (l1+r1+1)/2;
                if(r[mid]>=a)
                    r1=mid-1;
                else
                    l1 = mid;
            }
            if(r[l1]<a)
                bad+=l1+1;
            res=min(res,bad);
        }
        cout << res << "\n";
    }
    //cin.close();
    return 0;
}
