http://www.spoj.com/problems/NICEDAY/
//http://www.spoj.com/problems/NICEDAY/
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const int MAXN = 100005;
int c[MAXN];
struct Triple {
int a, b, c;
bool operator < (const Triple &t) const {
return a < t.a;
}
}triple[MAXN];
int lowbit(int n){
return n & (n ^ (n - 1));
}
int checkmin(int p){
int ret = c[p];
while (p) {
ret = min(ret, c[p]);
p -= lowbit(p);
}
return ret;
}
void update(int p, int v, int n) {
while (p <= n) {
c[p] = min(c[p], v);
p += lowbit(p);
}
}
int main()
{
int T, n;
cin>>T;
while (T--) {
cin>>n;
for (int i = 0; i < n; ++i) {
scanf("%d%d%d", &triple[i].a, &triple[i].b, &triple[i].c);
}
sort(triple, triple + n);
memset(c, 0x3f, sizeof(int) * (n + 1));
int excellent = 0;
for (int i = 0; i < n; ++i) {
int rank = checkmin(triple[i].b);
if (rank > triple[i].c) {
++excellent;
}
update(triple[i].b, triple[i].c, n);
}
cout<<excellent<<endl;
}
return 0;
}