#define _USE_MATH_DEFINES

#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <cassert>
#include <stack>
#include <cstdlib>
#include <bitset>
#include <cmath>

#define forn(i,n) for (int i = 0; i < int(n); ++i)
#define pb push_back
#define all(a) a.begin(),a.end()
#define sz(a) int(a.size())
#define mp make_pair

using namespace std;

typedef long long li;
typedef long double ld;

typedef pair<int,int> pt;
#define ft first
#define sc second

const int INF = int(1e9);
const li INF64 = li(1e18);
const ld EPS = 1e-9;

//#define TASK_NAME ""

const int N = 300 * 1000 + 5;

int n;
pair <int, pt> v[N];

bool read() {
	if (scanf("%d", &n) != 1)
		return false;
	forn(i, n)
		scanf("%d %d %d", &v[i].ft, &v[i].sc.ft, &v[i].sc.sc);
	return true;
}

int ft[N];

int get(int r) {
	int res = INF;
	for (; r >= 0; r = (r & (r + 1)) - 1)
		res = min(res, ft[r]);
	return res;
}

void upd(int pos, int u) {
	for (; pos < N; pos |= pos + 1)
		ft[pos] = min(ft[pos], u);
}

void solve() {
	forn(i, N)
		ft[i] = INF;

	sort(v, v + n);
	int res = 0;
	forn(i, n) {
		if (get(v[i].sc.ft) > v[i].sc.sc)
			res++;

		upd(v[i].sc.ft, v[i].sc.sc);
	}

	cout << res << endl;
}

int main() {
#ifdef TASK_NAME
	freopen(TASK_NAME ".in", "r", stdin);
	freopen(TASK_NAME ".out", "w", stdout);
#endif

#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif

	int t;
	scanf("%d", &t);

	while (read())
		solve();

	return 0;
}