# include <bits/stdc++.h>
using namespace std;

const int N = 200005;
struct Node{
    int l, r;
    int z;
    int y;
}node[N];

int l1[N];
int r1[N];


int main(){
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        for(int i=1; i<=n; i++){
            scanf("%d %d", &node[i].l, &node[i].r);
            l1[i] = node[i].l;
            r1[i] = node[i].r;
        }
    
        sort(l1 + 1, l1 + 1 + n);
        sort(r1 + 1, r1 + 1 + n);

        int ans = 100000005;
        for(int i=1; i<=n; i++){
        //    cout << node[i].l << ' ' << node[i].r << endl;
            int x = upper_bound(l1 + 1, l1 + 1 + n, node[i].r) - l1;
        //    cout << "x=" << x << endl;
            x = n - x + 1;
            int y = lower_bound(r1 + 1, r1 + 1 + n, node[i].l) - 1 - r1;
        //    cout << "y=" << y << endl;
        //    cout << x + y << endl;
            ans = min(x + y , ans);
        }
        
        cout << ans << endl;
    }



    return 0;
}

 			  			 	 			 	 			 	  	  	 	