# 1. 题目

n<=10^4,1<=坐标<=10^7

boshi&kb 已然用线段树 ac 了%%%%%

# 2. 题解

EASY,RIGHT?

#include <cstdio>
#include <map>
#include <cmath>
#include <cstring>
#define bi(a) ((a-1)/sqn+1)
using namespace std;
typedef pair<int,int> pii;typedef map<int,int> mii;
int n,sqn,arr[20100],sum[300],atag[300];
pii p[10100];
mii mp;
inline int getsum(int l,int r)
{
int ans=0;
for(int i=l;i<=min(r,bi(l)*sqn);i++)if(atag[bi(i)]||arr[i])ans++;
if(bi(l)!=bi(r))for(int i=(bi(r)-1)*sqn+1;i<=r;i++)ans+=atag[bi(i)]|arr[i];
for(int i=bi(l)+1;i<bi(r);i++)ans+=sum[i];
return ans;
}
inline void update(int l,int r)
{
for(int i=l;!atag[bi(l)]&&i<=min(r,bi(l)*sqn);i++)
sum[bi(i)]+=(arr[i]^1),arr[i]=1;
for(int i=(bi(r)-1)*sqn+1;bi(l)!=bi(r)&&!atag[bi(r)]&&i<=r;i++)
sum[bi(i)]+=(arr[i]^1),arr[i]=1;
for(int i=bi(l)+1;i<bi(r);i++)sum[i]=sqn,atag[i]=1;
}
int main()
{
int c,i,ans;
scanf("%d",&c);
while(c--)
{
memset(arr,0,sizeof(arr)),memset(sum,0,sizeof(sum));
memset(atag,0,sizeof(atag)),mp.clear(),ans=0;
scanf("%d",&n),sqn=sqrt(n);
for(i=1;i<=n;i++)
scanf("%d%d",&p[i].first,&p[i].second),
mp[p[i].first]=mp[p[i].second]=0;
i=1;
for(mii::iterator it=mp.begin();it!=mp.end();it++,i++)it->second=i;
for(i=1;i<=n;i++)p[i].first=mp[p[i].first],p[i].second=mp[p[i].second];
for(i=n;i>=1;i--)
ans+=getsum(p[i].first,p[i].second)<p[i].second-p[i].first+1,
update(p[i].first,p[i].second);
printf("%d\n",ans);
}
return 0;
}