#include<stdio.h>
struct Node
{
int start;
int end;
}a[10000];
void quick_sort(struct Node *arr, int l, int r)
{
if (l < r)
{
int i = l, j = r, x = arr[l].end;
struct Node temp = arr[l];
while (i < j)
{
while (i < j && x <= arr[j].end)
j--;
if (i < j)
arr[i++] = arr[j];
while (i < j && x > arr[i].end)
i++;
if (i < j)
arr[j--]= arr[i];
}
arr[i] = temp;
quick_sort(arr, l ,i - 1);
quick_sort(arr, i + 1, r);
}
}
int main()
{
int m, n, i, j;
scanf("%d",&m);
while (m--)
{
int num = 1;
scanf("%d",&n);
for (i = 0; i < n; i++)
scanf("%d%d",&a[i].start, &a[i].end);
quick_sort(a, 0, n - 1);
int t = 0, s = 1;
for (i = t; i < n; i++)
{
for (j = t + 1; j < n; j++)
{
if (a[j].start > a[t].end)
{
t = j;
num++;
s = 0;
}
}
if (s == 1)
t++;
s = 1;
}
printf("%d\n",num);
}
return 0;
}
--------------------------------------------------------------------------------