// Activity selection problem
#include
#include
using namespace std;
bool compare(pair<int,int> a,pair<int,int> b)
{
return a.second<b.second;
}
int main() {
int job=1;
int t; //test cases
cin>>t;
while(t>0)
{
int n;
// cout<<“enter the number of activities\n”;
cin>>n;
pair<int,int>act[n];
for(int i=0;i<n;i++)
{
cin>>act[i].first;
cin>>act[i].second;
}
sort(act,act+n,compare);
// for(int i=0;i<n;i++)
// {
// cout<<act[i].first<<" "<<act[i].second<<endl;
// }
// cout<<endl;
int last_ended=act[0].second;
for(int i=1;i<n;i++)
{
if(act[i].first>=last_ended)
{
// cout<<act[i].first<<" "<<act[i-1].second<<endl;
job++;
last_ended=act[i].second;
}
}
t–;
}
cout<<job<<endl;
return 0;
}