/** Nguyen Anh Tu **/
#include <bits/stdc++.h>
#define maxn 400005
#define maxc 1000000007
#define MOD 1000000007
#define task ""
#define mp make_pair
#define pb push_back
#define ep emplace_back
#define F first
#define S second
#define pii pair<int,int>
#define ll long long
#define bit(p,x) ((x>>p) & 1)
#define remain(a,b) (a+b >= MOD) ? (a+b - MOD) : (a+b)
#define mid ((l + r)/2)
#define Time   cerr << "Time collapse : " << fixed << setprecision(3) << 1.000*clock()/CLOCKS_PER_SEC

using namespace std;

int n, st[maxn], ed[maxn];
pii a[maxn];

void Solve(){
    cin >> n;
    vector<int> v;
    for(int i = 1; i <= n; ++ i){
        cin >> a[i].F >> a[i].S;
        v.pb(a[i].F);
        v.pb(a[i].S);
    }
    sort(v.begin(), v.end());
    v.resize(unique(v.begin(), v.end()) - v.begin());
    for(int i = 1; i <= n; ++ i){
        a[i].F = lower_bound(v.begin(), v.end(), a[i].F) - v.begin() + 1;
        a[i].S = lower_bound(v.begin(), v.end(), a[i].S) - v.begin() + 1;
        st[a[i].F] ++;
        ed[a[i].S] ++;
    }
    for(int i = 1; i <= 2 * n; ++ i){
        ed[i] += ed[i - 1];
    }
    for(int i = 2 * n - 1; i >= 1; -- i){
        st[i] += st[i + 1];
    }
    int ans = maxc;
    for(int i = 1; i <= n; ++ i){
        ans = min(ans, ed[a[i].F - 1] + st[a[i].S + 1]);
    }
    cout << ans << '\n';
    for(int i = 1; i <= 2 * n; ++ i){
        ed[i] = st[i] = 0;
    }
}

int main(){
    ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL);
    if(fopen(task".inp","r")){
        freopen(task".inp","r",stdin);
        freopen(task".out","w",stdout);
    }
    int t;
    cin >> t;
    while(t --){
        Solve();
    }
    Time;
    return 0;
}

