#include<bits/stdc++.h>
using namespace std ;
const int N=2e5;
vector<vector<int> >arr;
struct data
{
int a;
int b ;
int c ;
int ans;
};
data node[4*N+5];
void build(int i , int j , int index)
{
if(i==j)
{
node[index].a=arr[i][0];
node[index].b=arr[i][1];
node[index].c=arr[i][2];
node[index].ans=1;
return ;
}
int mid=(i+j)/2;
build(i,mid,2*index);
build(mid+1,j,2*index+1);
data l=node[2*index];
data r=node[2*index+1];
if(l.a<r.a&&l.b<r.b&&l.c<r.c)
{
node[index].ans=node[2*index].ans;
}
else
node[index].ans=l.ans+r.ans;
node[index].a=l.a;
node[index].b=l.b;
node[index].c=l.c;
}
int main ()
{
int t;
cin >> t ;
while(t--)
{
int n ;
cin >> n;
for (int i=0;i<n;i++)
{
int a, b , c;
cin >> a >> b >> c;
vector<int>temp;
temp.push_back(a);
temp.push_back(b);
temp.push_back(c);
arr.push_back(temp);
}
sort(arr.begin(),arr.end());
build(0,n-1,1);
cout<<node[1].ans<<"\n";
arr.clear();
}
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZCA7CmNvbnN0IGludCBOPTJlNTsKdmVjdG9yPHZlY3RvcjxpbnQ+ID5hcnI7CnN0cnVjdCBkYXRhCnsKCWludCBhOwoJaW50IGIgOwoJaW50IGMgOwoJaW50IGFuczsKfTsKZGF0YSBub2RlWzQqTis1XTsKdm9pZCBidWlsZChpbnQgaSAsIGludCBqICwgaW50IGluZGV4KQp7CglpZihpPT1qKQoJewoJCW5vZGVbaW5kZXhdLmE9YXJyW2ldWzBdOwoJCW5vZGVbaW5kZXhdLmI9YXJyW2ldWzFdOwoJCW5vZGVbaW5kZXhdLmM9YXJyW2ldWzJdOwoJCW5vZGVbaW5kZXhdLmFucz0xOwoJCXJldHVybiA7Cgl9CglpbnQgbWlkPShpK2opLzI7CglidWlsZChpLG1pZCwyKmluZGV4KTsKCWJ1aWxkKG1pZCsxLGosMippbmRleCsxKTsKCWRhdGEgbD1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