#include<stdio.h>
struct Node
{
    int weight;
    int s;   //根据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)    //从右往左找一个小于x的数
                j--;
            if (i < j)
                arr[i++] = arr[j];
            while (i < j && x > arr[i].weight)     //从左往右找一个大于x的数
                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;     //num用来计数
        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;
}