#include <cstdio>
#include <vector>
#include <algorithm>

#pragma warning (disable : 4996)

using namespace std;

typedef long long LL;

struct EvP {
	int t;
	int pm;
	int v;
	bool operator < (const EvP &that) {
		return this->t < that.t  ||  this->t == that.t && this->pm < that.pm;
	}
	bool operator <= (const EvP &that) {
		return this->t < that.t  ||  this->t == that.t && this->pm <= that.pm;
	}
	EvP(int t_, int pm_, int v_) : t(t_), pm(pm_), v(v_) { } ;
};


int main()
{
 #ifdef _DEBUG
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
 #endif
	int TEST_NUM;
	scanf("%d", &TEST_NUM);
	for(int the_test = 0; the_test < TEST_NUM; the_test++) {
		int n;
		scanf("%d", &n);
		vector<EvP> heat_in, heat_out;
		long long tot_heat_have = 0LL, tot_heat_need = 0LL;
		for(int i=0; i<n; i++) {
			int vol, t_start, t_finish;
			scanf("%d %d %d", &vol, &t_start, &t_finish);
			tot_heat_have += (LL)vol * (LL)t_start;
			tot_heat_need += (LL)vol * (LL)t_finish;
			if(t_start < t_finish) {
				heat_in.push_back(EvP(t_start, +1, vol));
				heat_in.push_back(EvP(t_finish, -1, vol));
			} else if(t_start > t_finish) {
				heat_out.push_back(EvP(t_start, -1, vol));
				heat_out.push_back(EvP(t_finish, +1, vol));
			} // if t_start == t_finish, we completely skip this cup
		};
		if(tot_heat_have != tot_heat_need) {
			printf("NIE\n");
			continue;
		}
		if(heat_in.empty() ^ heat_out.empty()) { 
			// this is probably already checked by previuos if, but I still have some doubts...
			printf("NIE\n");
			continue;
		}
		sort(heat_in.begin(), heat_in.end());
		sort(heat_out.begin(), heat_out.end());
		size_t i_in = 0, i_out = 0;
		int prev_t = min(heat_in[0].t, heat_out[0].t);
		LL curr_hpd_in = 0LL, curr_hpd_out = 0LL;
		LL curr_heat_left = 0LL;
		bool was_breaked = false;
		while(i_in < heat_in.size() || i_out < heat_out.size()) {
			int curr_t;
			if(i_out >= heat_out.size()  ||  i_in < heat_in.size() && heat_in[i_in] <= heat_out[i_out]) {
				curr_t = heat_in[i_in].t;
				curr_heat_left += (curr_t - prev_t) * (curr_hpd_out - curr_hpd_in);
				curr_hpd_in += heat_in[i_in].v * heat_in[i_in].pm;
				i_in++;
			} else if(i_in >= heat_in.size() || i_out < heat_out.size() && heat_out[i_out] <= heat_in[i_in]){
				curr_t = heat_out[i_out].t;
				curr_heat_left += (curr_t - prev_t) * (curr_hpd_out - curr_hpd_in);
				curr_hpd_out += heat_out[i_out].v * heat_out[i_out].pm;
				i_out++;
#ifdef _DEBUG
			} else {
				_DEBUG_ERROR("Why is this possible?!?");
#endif
			}
			if(curr_heat_left > 0LL) {
				was_breaked = true;
				printf("NIE\n");
				break;
			}
			prev_t = curr_t;
		}
		if(!was_breaked) {
			printf("TAK\n");
		}
	}
}




/*************************************
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

typedef pair<int,int> pii;
typedef long long LL;

int main()
{
 #ifdef _DEBUG
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
 #endif
	int TEST_NUM;
	scanf("%d", &TEST_NUM);
	for(int the_test = 0; the_test < TEST_NUM; the_test++) {
		int n;
		scanf("%d", &n);
		vector<pii> have(n), need(n);
		long long tot_heat_have = 0LL, tot_heat_need = 0LL;
		long long tot_volume = 0LL;
		for(int i=0; i<n; i++) {
			scanf("%d %d %d", &(have[i].second), &(have[i].first), &(need[i].first));
			need[i].second = have[i].second;
			tot_heat_have += (LL)have[i].first * (LL)have[i].second;
			tot_heat_need += (LL)need[i].first * (LL)need[i].second;
			tot_volume += have[i].second;
		};
		if(tot_heat_have != tot_heat_need) {
			printf("NIE\n");
			continue;
		}
		sort(have.begin(), have.end());
		sort(need.begin(), need.end());
		long long curr_heat_have = 0LL, curr_heat_need = 0LL;
///		long long curr_vol_have = 0LL, curr_vol_need = 0LL;
		int i_have=0, i_need=0;
		double overall_mid_temp = tot_heat_have / tot_volume;
		bool was_breaked = false;
		while(i_have < n && i_need < n) {
			int curr_temp = min(have[i_have].first, need[i_need].first);
			while(i_have < n && have[i_have].first == curr_temp) {
				curr_heat_have += (LL)have[i_have].first * (LL)have[i_have].second;
///				curr_vol_have += have[i_have].second;
				i_have++;
			}
			while(i_need < n && need[i_need].first == curr_temp) {
				curr_heat_need += (LL)need[i_need].first * (LL)need[i_need].second;
///				curr_vol_need += need[i_need].second;
				i_need++;
			}

			// TODO: враховувати, яка сумарна теплоємність "у процесі" зменшення/збільшення
			// (для чого, повернутися до того, що двома способами відсортовані все-таки трійки, а не пари)

///			if(curr_vol_need >= curr_vol_have && curr_heat_need < curr_heat_have) {
			if(curr_heat_need < curr_heat_have) {
				printf("NIE\n");
				was_breaked = true;
				break;
			}
		}
		if(!was_breaked) {
			printf("TAK\n");
		}
	}
	return 0;
}
*****************************************************/