#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<ctime>
#define ll long long
using namespace std;
const int maxx=600010;
const double pi=acos(-1.0);
const double eps=1e-15;
int t,n,m;
int ans=0,total=0,sum=0,cnt=0,l=0,r=0;
int a[maxx],b[maxx],bj[maxx];
struct node
{
	int l;
	int r;
}s[maxx];
int main()
{
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
		ans=1e8;
		for(int i=1;i<=n;i++)scanf("%d%d",&s[i].l,&s[i].r),a[i]=s[i].l,b[i]=s[i].r;
		sort(a+1,a+n+1);
		sort(b+1,b+n+1);
		for(int i=1;i<=n;i++)
		{
			sum=0;
			int l1=s[i].l,r1=s[i].r;
			int u1=upper_bound(a+1,a+n+1,s[i].r)-a,u2=lower_bound(b+1,b+n+1,s[i].l)-b-1;
			if(a[u1]>s[i].r)sum+=n-u1+1;
			sum+=u2;
			ans=min(ans,sum);
		} 
		printf("%d\n",ans);
	}
	return 0;
}
