#include using namespace std; // OM NAMAH SHIVAY // #include // #include // using namespace __gnu_pbds; // typedef tree, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key #define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define endl "\n" #define int long long const int inf = 1e18; // int dx[4]={-1,0,1,0}; // int dy[4]={0,1,0,-1}; // int dx[8]={0,-1,-1,-1,0,1,1,1}; // int dy[8]={1,1,0,-1,-1,-1,0,1}; const int N = 200200; const int mod = 1e9+7; using ii = pair; //write on copy void solver(){ int n; cin>>n; multisets; for(int i=0;i>a>>b; s.insert({a,b}); } int ans = 0; while(s.size()>1) { auto it = s.begin(); int y = it->second; s.erase(s.begin()); ans++; while(1) { auto it = s.lower_bound({y,0}); if(it==s.end()) break; int y = it->second; s.erase(it); } } cout<>_t;while(_t--) solver(); return 0; } #undef int