// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
using namespace std;
// mylittledoge
struct fin {
vector<int> T;
fin(int N) {T.resize(N+1,N+1);}
int lastone(int x) {return x&(x^(x-1));}
void put(int pos, int val) {
for(int i =pos+1; i < T.size(); i +=lastone(i)) T[i] =min(T[i],val);
}
int get(int pos) {
int ret =OVER9000;
for(int i =pos+1; i > 0; i -=lastone(i)) ret =min(ret,T[i]);
return ret;}
};
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
int T;
cin >> T;
for(int t =0; t < T; t++) {
int N;
cin >> N;
vector< pair<int,int> > V(N);
for(int i =0; i < N; i++) {
int a,b,c;
cin >> a >> b >> c;
V[a-1] =make_pair(b,c);}
fin F(N+tisic);
int ans =0;
for(int i =0; i < N; i++) {
if(F.get(V[i].ff) > V[i].ss) ans++;
F.put(V[i].ff,V[i].ss);}
cout << ans << "\n";}
return 0;}
// look at my code
// my code is amazing
Ly8gaW9zdHJlYW0gaXMgdG9vIG1haW5zdHJlYW0KI2luY2x1ZGUgPGNzdGRpbz4KLy8gYml0Y2ggcGxlYXNlCiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPGNzdGRsaWI+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxzZXQ+CiNpbmNsdWRlIDxtYXA+CiNpbmNsdWRlIDxxdWV1ZT4KI2luY2x1ZGUgPHN0YWNrPgojaW5jbHVkZSA8bGlzdD4KI2lu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