#include<iostream>
#include<vector>
#include<algorithm>
struct Wood
{
int l, w;
bool processed;
};
int n, m;
using namespace std;
bool cmp(Wood &a, Wood&b)
{
if (a.l == b.l) return a.w < b.w;
else return a.l < b.l;
}
bool all_processed(vector<Wood>a)
{
bool is = true;
for (int i = 0; i < m; i++)
{
if (!a[i].processed) is = false;
}
return is;
}
int main(void)
{
int n;
cin >> n;
while (n--)
{
cin >> m;
vector<Wood>a(m);
for (int i = 0; i < m; i++)
{
cin >> a[i].l >> a[i].w;
a[i].processed = false;
}
sort(a.begin(),a.end(), cmp);
int set_time=0;
int temp;
while (!all_processed(a))
{
for (int i = 0; i < m; i++)
{
if (!a[i].processed)
{
temp = i;
break;
}
}
int start = temp;
a[temp].processed = true;
for (int j = start+1; j < m; j++)
{
if ((a[temp].l <= a[j].l&&a[temp].w <= a[j].w)&&!a[j].processed)
{
temp = j;
a[j].processed = true;
}
}
set_time++;
}
cout << set_time << endl;
}
return 0;
}
#include<vector>
#include<algorithm>
struct Wood
{
int l, w;
bool processed;
};
int n, m;
using namespace std;
bool cmp(Wood &a, Wood&b)
{
if (a.l == b.l) return a.w < b.w;
else return a.l < b.l;
}
bool all_processed(vector<Wood>a)
{
bool is = true;
for (int i = 0; i < m; i++)
{
if (!a[i].processed) is = false;
}
return is;
}
int main(void)
{
int n;
cin >> n;
while (n--)
{
cin >> m;
vector<Wood>a(m);
for (int i = 0; i < m; i++)
{
cin >> a[i].l >> a[i].w;
a[i].processed = false;
}
sort(a.begin(),a.end(), cmp);
int set_time=0;
int temp;
while (!all_processed(a))
{
for (int i = 0; i < m; i++)
{
if (!a[i].processed)
{
temp = i;
break;
}
}
int start = temp;
a[temp].processed = true;
for (int j = start+1; j < m; j++)
{
if ((a[temp].l <= a[j].l&&a[temp].w <= a[j].w)&&!a[j].processed)
{
temp = j;
a[j].processed = true;
}
}
set_time++;
}
cout << set_time << endl;
}
return 0;
}