#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>

using namespace std;

#ifdef SG
#include <debug.h>
#else
#define show(...)
#define debug(...)
#define deepen(...)
#define timer(...)
#endif

#define ARG4(_1,_2,_3,_4,...) _4

#define forn3(i,l,r) for (int i = int(l); i < int(r); ++i)
#define forn2(i,n) forn3 (i, 0, n)
#define forn(...) ARG4(__VA_ARGS__, forn3, forn2) (__VA_ARGS__)

#define ford3(i,l,r) for (int i = int(r) - 1; i >= int(l); --i)
#define ford2(i,n) ford3 (i, 0, n)
#define ford(...) ARG4(__VA_ARGS__, ford3, ford2) (__VA_ARGS__)

#define ve vector
#define pa pair
#define tu tuple
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fs first
#define sc second
#define all(a) (a).begin(), (a).end()
#define sz(a) ((int)(a).size())
#define forsn(i, s, n) for(int i = (s); i < (n); ++i)
#define forn(i, n) forsn(i, 0, n)

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

typedef pa<int, int> pii;
typedef pa<int, ll> pil;
typedef pa<ll, int> pli;
typedef pa<ll, ll> pll;
typedef ve<int> vi;

const ld pi = 3.1415926535897932384626433832795l;

template<typename T> inline auto sqr(T x) -> decltype(x * x) { return x * x; }
template<typename T1, typename T2> inline bool umx(T1& a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool umn(T1& a, T2 b) { if (b < a) { a = b; return 1; } return 0; }

typedef pll pt;
#define x first
#define y second

pt operator + (const pt &a, const pt &b) {
	return pt(a.x + b.x, a.y + b.y);
}

pt operator - (const pt &a, const pt &b) {
	return pt(a.x - b.x, a.y - b.y);
}

int operator * (const pt &a, const pt &b) {
	return a.x * b.x + a.y * b.y;
}

int operator ^ (const pt &a, const pt &b) {
	return a.x * b.y - a.y * b.x;
}

const int N = 2000;

struct Input {
	int n, m;
	pt a[N], b[N];

	void read() {
		n = 0;
		m = 0;
		int total;
		cin >> total;
		int tx, ty, type;
		forn(i, total) {
			cin >> tx >> ty >> type;

			if (type == 0) {
				a[n].x = tx;
				a[n].y = ty;
				++n;
			}
			if (type == 1) {
				b[m].x = tx;
				b[m].y = ty;
				++m;
			}
		}
	}

	void init(const Input &input) {
		*this = input;
	}
};

struct Data : Input {
	bool ans;

	void write() {
		puts(ans ? "YES" : "NO");
	}

	virtual void solve() {}

	virtual void clear() {
		*this = Data();
	}
};

struct Solution : Data {
	bool static in(pt a[N], int n, pt o) {
		forn(i, n) {
			if (a[i] == o) {
				return 1;
			}
		}
		forn(i1, n) {
			forn(i2, i1) {
				if (((a[i1] - o) ^ (a[i2] - o)) == 0 && ((a[i1] - o) * (a[i2] - o)) < 0) {
					return 1;
				}
			}
		}
		auto cmp = [&](const pt &a, const pt &b) {
			return ((a - o) ^ (b - o)) > 0;
		};
		sort(a, a + n, cmp);
		forn(i1, n) {
			forn(i2, i1) {
				if (cmp(a[i1], a[i2])) {
					return 1;
				}
			}
		}
		return 0;
	}

	inline static int sgn(int x) {
		if (x < 0) {
			return -1;
		}
		return x > 0;
	}

	inline static bool isct(pt a, pt b, pt c, pt d) {
		if (((a - b) ^ (c - d)) == 0) {
			if (((a - b) ^ (a - c)) != 0) {
				return 0;
			}
			if (a > b) {
				swap(a, b);
			}
			if (c > d) {
				swap(c, d);
			}
			return (a <= d) && (b >= c);
		}
		return (
			sgn(((a - c) ^ (a - d))) * sgn(((b - c) ^ (b - d))) <= 0 &&
			sgn(((c - a) ^ (c - b))) * sgn(((d - a) ^ (d - b))) <= 0
			);
	}

	void solve() {
		forn(i, n) {
			if (in(b, m, a[i])) {
				ans = 0;
				return;
			}
		}
		forn(i, m) {
			if (in(a, n, b[i])) {
				ans = 0;
				return;
			}
		}
		forn(i1, n) {
			forn(i2, i1) {
				forn(j1, m) {
					forn(j2, j1) {
						if (isct(a[i1], a[i2], b[j1], b[j2])) {
							ans = 0;
							return;
						}
					}
				}
			}
		}
		ans = 1;
	}

	void clear() {
		*this = Solution();
	}
};

Solution sol;

int main() {
	cout.setf(ios::showpoint | ios::fixed);
	cout.precision(20);
	int datasets;
	cin >> datasets;
	forn(i, datasets) {
		sol.read();
		sol.solve();
		sol.write();
		sol.clear();
	}
	return 0;
}
