1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#pragma GCC optimize("O3")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,n) for (auto i ## __ = (n), i = (a); i <= i ## __; ++i)
#define FORD(i,a,n) for (auto i ## __ = (n), i = (a); i >= i ## __; --i)
#define REP(i,n) FOR(i,0,(n) - 1)
#define ALL(h) begin(h), end(h)
#define EB emplace_back
#define X first
#define Y second
#define V vector
#define tpv typedef V<

typedef long long LL;
typedef pair<int, int> PII;
tpv int> VI;
tpv VI> VVI;
tpv PII> VPII;
tpv LL> VLL;

constexpr char nl = '\n';
#define endl nl
#define ris return *this
#define tem template<class t

tem, class u> inline void mini(t& a, u&& b) { if (b < a) a = b; }
tem, class u> inline void maxi(t& a, u&& b) { if (b > a) a = b; }
int ceil2(int h) { return h < 2 ? 1 : 1 << (sizeof(h) * 8 - __builtin_clz(h - 1)); }

tem> struct Dump { t a, b; };
tem> auto dump(t&& h) -> Dump<decltype(begin(h))> { return {ALL(h)}; }
tem> auto stub(t* h) -> decltype(cerr << *h, 0);
tem> char stub(...);
#define enif(o) tem> typename enable_if<sizeof stub<t>(0) o 1, debug&>::type operator<<(t h)
#define dor > debug& operator<<
struct debug {
#ifdef DEBUG
#define deb debug()
	~debug() { cerr << nl; }
	enif(!=) { cerr << boolalpha << h; ris; }
	enif(==) {
		*this << '{';
		for (auto a = begin(h), b = end(h); a != b;)
			*this << *a++ << &" "[a == b];
		ris << '}';
	}
	tem, class u dor(pair<t, u> p) { ris << '(' << p.X << ", " << p.Y << ')'; }
	tem dor(Dump<t> d) {
		*this << "{\n";
		for (t a = d.a, c = a; a != d.b; ++a)
			*this << "  " << distance(c, a) << ": " << *a << nl;
		ris << '}';
	}
#else
	operator int() { return 0; }
	tem dor(t&&) { ris; }
#define deb 0 and debug()
#endif
};

#define imie(h...) #h ": " << (h) << " "
#define LOG(h...) deb << imie(h)
#define DOG(h...) deb << #h ": " << dump(h) << " "

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	int t;
	cin >> t;

	while (t--) {
		int n;
		cin >> n;
		int mn1 = 1e9, mx1 = 0;
		int mn2 = 1e9, mx2 = 0;
		LL sum_temp1 = 0;
		LL sum_temp2 = 0;
		while (n--) {
			int ile, temp1, temp2;
			cin >> ile >> temp1 >> temp2;
			mn1 = min(mn1, temp1);
			mx1 = max(mx1, temp1);
			mn2 = min(mn2, temp2);
			mx2 = max(mx2, temp2);
			sum_temp1 += ile * temp1;
			sum_temp2 += ile * temp2;
		}
		LOG(sum_temp1);
		LOG(mn1);
		LOG(mn2);
		LOG(mx1);
		LOG(mx2);
		if (sum_temp1 == sum_temp2 && mn1 <= mn2 && mx2 <= mx1)
			cout << "TAK" << endl;
		else
			cout << "NIE" << endl;
	}

	return 0;
}
/*
1
79
564 3198 3059
37 3109 2763
308 2957 3144
386 3548 3438
259 3525 3586
411 3418 2718
190 3385 3226
825 3364 3618
666 3521 2698
218 3569 2772
809 3338 3193
268 2668 2781
367 2677 3606
494 3309 3014
656 3215 3071
579 3048 2965
901 3000 2971
1 1 2655
245 3311 3475
4 3394 3576
292 3310 3482
298 3269 2975
178 3120 3516
683 3090 3593
760 3463 3188
935 3523 3166
60 2801 3221
173 3236 3155
198 3319 3434
900 3291 3221
388 2749 3533
774 3300 3582
871 2869 3577
709 3371 3198
793 3269 3533
238 3244 3001
707 3170 3049
561 3209 3343
382 3376 3383
983 2899 3445
950 3087 3134
746 3577 3203
407 2794 2700
903 3050 3396
150 3063 2727
197 3450 3596
976 3360 2758
12 2767 2708
845 2972 3311
685 3253 3212
702 3278 3498
231 3363 3130
128 3093 2978
22 3436 3477
675 3621 3268
608 2722 3241
334 3265 3003
469 2660 2717
230 2955 2843
160 3640 3377
581 3257 2848
425 3220 3273
949 3533 2657
923 3371 3096
707 3027 3127
71 3192 3146
808 2737 3414
455 3213 3236
194 2804 2869
132 3039 2808
441 2812 3450
510 3055 3084
273 3525 3449
574 3314 3571
677 2842 3203
511 3444 2698
238 3371 3599
382 2712 3402
784 3501 3209

5
2
2 1 4
2 5 2
2
1 4 3
1 5 4
2
1 5 7
1 7 5
2
1 4 1
1 2 5
3
2 6 4
1 2 3
3 4 5
*/