#include<iostream>
#include<algorithm>

using namespace std;

const int N = 2e5 + 10;

struct node{
	int x,y;
}a[N],b[N];

int n,m;

bool cmp(node a,node b){
	return a.x < b.x;
}

bool cmp1(node a,node b){
	return a.y < b.y;
}

int c[N],d[N]; 

int main(){
	int t;
	cin >> t;
	while(t--){
		cin >> n;
		for(int i = 1; i <= n; i++){
			cin >> a[i].x >> a[i].y;
			b[i].x = a[i].x,b[i].y = a[i].y;
		}
		
		int maxn = 0x3f3f3f3f;
		sort(a + 1,a + n + 1,cmp);
		for(int i = 1; i <= n; i++){
			int sum = 0;
			int l = 1,r = n;
			while(l < r){
				int mid = l + r + 1 >> 1;
				if(b[i].y < a[mid].x){ 
					r = mid - 1;
				}else l = mid;
			}
			if(a[r].x > b[i].y){
				sum += n - r + 1;
			}else sum += n - r;
			c[i] = sum;
		}
		sort(a + 1,a + n + 1,cmp1);
		for(int i = 1; i <= n; i++){ 
			int sum = 0;
			int l = 1,r = n;
			while(l < r){
				int mid = l + r + 1 >> 1;
				if(b[i].x > a[mid].y){
					l = mid;
				}else r = mid - 1;
			}
			if(a[l].y < b[i].x){
				sum += l;
			}else if(a[l].y == b[i].x){
				sum += l - 1;
			}
			d[i] = sum;
		}
		
		for(int i = 1; i <= n; i++){
			maxn = min(maxn,c[i] + d[i]);
		}
		
		cout << maxn << endl;
	}
	
	
	
	return 0;
}