#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <algorithm>
#include<queue>
using namespace std;

struct pr
{
	int a, b, c;
	pr(int ae = 0, int be = 0, int ce = 0)
	{
		a = ae;
		b = be;
		c = ce;
	}
	bool operator <(const pr& p) const
	{
		return a < p.a;
	}
};

int n;

int a[100005];

void add(int p, int v)
{
	for(int i = p; i < n; i |= (i+1))
		a[i] = min(a[i], v);
}
int inf = 1000000000;
int mn(int p)
{
	int res = inf;
	for(int i = p; i >= 0; i = (i & (i+1))-1)
		res = min(a[i], res);
	return res;
}

pr b[100005];

int main()
{
	int T;
	scanf("%d", &T);
	while(T)
	{
		T--;
		scanf("%d", &n);
		for(int i = 0; i < n; i++)
			a[i] = inf;
		for(int i = 0; i < n; i++)
			scanf("%d%d%d", &b[i].a, &b[i].b, &b[i].c);
		sort(b, b+n);

		int res = 0;
		for(int i = 0; i < n; i++)
		{
			if(mn(b[i].b-1) > b[i].c)
			{
				res++;
				add(b[i].b, b[i].c);
			}
		}
		printf("%d\n", res);
	}
	
	return 0;
}