#ifdef SU1
#define _GLIBCXX_DEBUG
#endif

#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdio>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forl(i, n) for (int i = 1; i <= int(n); i++)
#define ford(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define fore(i, l, r) for (int i = int(l); i <= int(r); i++)
#define pb(a) push_back(a)
#define mp(x, y) make_pair((x), (y))
#define sz(a) (int) (a).size()
#define all(a) (a).begin(), (a).end()
#define ft first
#define sc second
#define x first
#define y second

template<typename X> inline X abs(const X& a) { return a < 0 ? -a : a; }
template<typename X> inline X sqr(const X& a) { return a * a; }

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

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

const int N = 100 * 1000 + 13;

int a[N][3];
int n;
int perm[N];
int t[4 * N];

inline bool read()
{
	if (scanf("%d", &n) != 1) return false;
	forn(i, n)
	{
		forn(j, 3) assert(scanf("%d", &a[i][j]) == 1), a[i][j]--;
		perm[i] = i;
	}
	return true;
}

inline bool cmp (int x, int y)
{
	return a[x][0] < a[y][0];
}

int min (int idx, int lf, int rg, int l, int r)
{
	if (lf == l && rg == r) return t[idx];
	
	int mid = (lf + rg) >> 1;
	int res = INF;
	
	if (l <= mid) res = min(res, min(2 * idx + 1, lf, mid, l, min(mid, r)));
	if (r > mid) res = min(res, min(2 * idx + 2, mid + 1, rg, max(mid + 1, l), r));
	
	return res;
}

void upd (int idx, int lf, int rg, int pos, int val)
{
	if (lf == rg) t[idx] = val;
	else
	{
		int mid = (lf + rg) >> 1;
		if (pos <= mid) upd(2 * idx + 1, lf, mid, pos, val);
		else upd(2 * idx + 2, mid + 1, rg, pos, val);
		t[idx] = min(t[2 * idx + 1], t[2 * idx + 2]);
	}
}

inline void solve()
{
	memset(t, 63, sizeof(t));
	
	sort(perm, perm + n, cmp);
	
	int ans = 0;
	
	forn(i, n)
	{
		int idx = perm[i];
		
		int minv = min(0, 0, n - 1, 0, a[idx][1]);
		
		if (minv > a[idx][2]) ans++;
		
		upd(0, 0, n - 1, a[idx][1], a[idx][2]);
	}
	
	cout << ans << endl;
}

int main()
{
#ifdef SU1
	assert(freopen("input.txt", "rt", stdin));
//	assert(freopen("output.txt", "wt", stdout));
#endif

	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(5);
	
	int testCount;
	cin >> testCount;
	
	forn(test, testCount)
	{
		assert(read());
		solve();
	}
	
#ifdef SU1
	cerr << "=== TIME : " << clock() << " ===" << endl;
#endif
	return 0;
}
