#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;
struct pt
{
	int x, y, z;
	friend bool operator < (pt q, pt w)
	{
		return q.x < w.x;
	}
};
int ytoz[100001];
int main()
{
	int t;
	cin >> t;
	for (int i = 0; i < t; ++i)
	{
		int n;
		cin >> n;
		vector<pt> arr(n);
		for (int i = 0; i < n; ++i)
		{
			cin >> arr[i].x >> arr[i].y >> arr[i].z;
			//arr[i].x = n - arr[i].x;
			arr[i].y = n - arr[i].y;
			arr[i].z = n - arr[i].z;
			ytoz[arr[i].y] = arr[i].z;
		}
		sort(arr.begin(), arr.end());
		set<int> S;
		int ans = 0;
		for (int i = 0; i < n; ++i)
		{
			set<int> ::iterator itr = S.lower_bound(arr[i].y);
			//cout << arr[i].x << " " << arr[i].y << " " << arr[i].z << endl; 
			if (itr != S.end() && ytoz[*itr] > ytoz[arr[i].y])
			{
				++ans;
				//cout << "-" << endl;
				continue;
			}
			else
			{
				S.insert(arr[i].y);
				itr = S.lower_bound(arr[i].y);
				if (itr == S.begin())
					continue;
				--itr;
				while (itr != S.begin() && ytoz[arr[i].y] > ytoz[*itr])
				{
					set<int>::iterator itr1 = itr;
					if (itr1 != S.begin())
						--itr1;
					S.erase(itr);
					itr = itr1;
				}
			}
		}
		cout << n - ans << endl;
	}
	//system ("pause");
	return 0;
}