#include<stdio.h>
#include<algorithm>
using namespace std;
struct activity
{
int start;
int end;
}a[10000];
bool cmp(struct activity a,struct activity b)
{
if(a.end != b.end) return a.end < b.end;
else return a.start < b.start;
}
int main()
{
int n,c,i,times,end;
scanf("%d",&n);
while(n--)
{
times = 1;
scanf("%d",&c);
for(i = 0;i < c;i++)
{
scanf("%d %d",&a[i].start,&a[i].end);
}
sort(a,a+c,cmp);
end = a[0].end;
for(i = 1;i < c;i++)
{
if(a[i].start > end)
{
times++;
end = a[i].end;
}
}
printf("%d\n",times);
}
return 0;
}
#include<algorithm>
using namespace std;
struct activity
{
int start;
int end;
}a[10000];
bool cmp(struct activity a,struct activity b)
{
if(a.end != b.end) return a.end < b.end;
else return a.start < b.start;
}
int main()
{
int n,c,i,times,end;
scanf("%d",&n);
while(n--)
{
times = 1;
scanf("%d",&c);
for(i = 0;i < c;i++)
{
scanf("%d %d",&a[i].start,&a[i].end);
}
sort(a,a+c,cmp);
end = a[0].end;
for(i = 1;i < c;i++)
{
if(a[i].start > end)
{
times++;
end = a[i].end;
}
}
printf("%d\n",times);
}
return 0;
}