#include<iostream>
#include<cstring>
#include<map>
#include<algorithm>
#include<stack>
#include<queue>
#include<cstdio>
#include<cmath>
#include<string.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+10;
const int inf=99999999;
const int mod=1e9+7;
int a[maxn],b[maxn],x[maxn],y[maxn];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i]>>b[i];
x[i]=a[i];
y[i]=b[i];
}
sort(x+1,x+1+n);
sort(y+1,y+1+n);
ll minn = inf;
for(int i=1;i<=n;i++)
{
ll l=lower_bound(y+1,y+1+n,a[i])-y-1;
ll r=n-(upper_bound(x+1,x+1+n,b[i])-x)+1;
minn=min(minn,l+r);
}
cout<<minn<<endl;
}
}