#include <bits/stdc++.h>
#define xx first
#define yy second
#define N 200010
using namespace std;
int n,t,l[N],r[N],i,k;
pair<int,int> a[N];
int main(){
	cin>>t;
	while(t--){
		cin>>n;
		int ans=n;
		for(i=0;i<n;i++){
			cin>>l[i]>>r[i];
			a[i].xx=l[i];
			a[i].yy=r[i];
		}
		sort(l,l+n);
		sort(r,r+n);
		for(i=0;i<n;i++){
			k=lower_bound(r,r+n,a[i].xx)-r;
			k+=n-(upper_bound(l,l+n,a[i].yy)-l);
			ans=min(ans,k);
		}
		cout<<ans<<"\n";
	}
}