#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 10005
struct node
{
long l,r,h;
};
long buildTree(long l,long r,long pos);
void addHeight(long l,long r,long pos,long h);
void dealData(long &n,long pos);
node old[MAXN],newT[MAXN * 10];
bool isShowed[MAXN];
long tn,num,index[MAXN * 2];
int main()
{
int t,n;
scanf("%d",&t);
while(t --)
{
memset(old,0,sizeof(old));
memset(newT,0,sizeof(newT));
memset(index,0,sizeof(index));
memset(isShowed,false,sizeof(isShowed));
int i,j;
num = tn = 0;
scanf("%d",&n);
for(i = 0 ; i < n ; i ++)
scanf("%ld %ld",&old[i].l , &old[i].r) ,old[i].h = i + 1
, index[num ++] = old[i].l - 1 , index[num ++] = old[i].r;
sort(index , index + num);
j = 1;
for(i = 1 ; i < num ; i ++)
if(index[i] != index[j - 1])
index[j ++] = index[i];
index[j] = index[j - 1] + 1;
num = j;
buildTree(0,num - 1, 1);
for(i = 0 ; i < n ; i ++)
addHeight(old[i].l - 1 , old[i].r ,1, old[i].h);
dealData(tn , 1);
j = 0;
for(i = 0 ; i < MAXN ; i ++)
j += isShowed[i]?1:0;
printf("%d\n",j);
}
return 0;
}
long buildTree(long l,long r,long pos)
{
newT[pos].l = l;
newT[pos].r = r;
newT[pos].h = 0;
long mid = (l + r) >> 1;
tn = (pos > tn)? pos : tn;
if(r > l + 1)
return 1 + buildTree(l , mid, 2 * pos) + buildTree(mid , r, 2 * pos + 1);
else
return 1;
}
void addHeight(long l,long r,long pos,long h)
{
if(l == index[newT[pos].l] && r == index[newT[pos].r])
{
newT[pos].h = h;
return;
}
if(newT[pos].l >= newT[pos].r)
return;
long mid = (newT[pos].l + newT[pos].r) >> 1;
if(newT[pos].h)
{
newT[2 * pos].h = newT[pos].h;
newT[2 * pos + 1].h = newT[pos].h;
newT[pos].h = 0;
}
if(index[mid] >= r)
addHeight(l,r,2 * pos, h);
else if(index[mid] <= l)
addHeight(l,r,2 * pos + 1, h);
else
{
addHeight(l,index[mid],2 * pos, h);
addHeight(index[mid],r,2 * pos + 1, h);
}
}
void dealData(long &n,long pos)
{
if(newT[pos].h)
{
isShowed[newT[pos].h] = true;
return;
}
if(2 * pos <= tn)
dealData(n,2 * pos);
if(2 * pos + 1 <= tn)
dealData(n,2 * pos + 1);
}