
#include<stdio.h>
struct Node
{
int weight;
int s;
int length;
}a[5001];
void quick_sort(struct Node *arr, int l, int r)
{
if (l < r)
{
int i = l, j = r, x = arr[l].weight;
struct Node temp = arr[l];
while (i < j)
{
while (i < j && x <= arr[j].weight)
j--;
if (i < j)
arr[i++] = arr[j];
while (i < j && x > arr[i].weight)
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;
scanf("%d",&m);
while (m--)
{
int n, i, j = 1;
scanf("%d",&n);
for (i = 0; i < n; i++)
scanf("%d%d",&a[i].weight, &a[i].length);
quick_sort(a, 0, n - 1);
int t = 0, num = 1;
for (i = 0; i < n; i++)
a[i].s = 1;
for (i = 0; i < n; i++)
{
for (; j < n; j++)
{
if (a[t].length <= a[j].length && a[j].s == 1)
{
t = j;
a[j].s = 0;
}
}
for (j = 1; j < n; j++)
{
if (a[j].s == 1)
{
t = j;
num++;
break;
}
}
if (j == n)
break;
}
printf("%d\n",num);
}
return 0;
}