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
// Author: Piotr Grzegorczyk

#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

void process(vector<int> & v) {
	int m = v[0];
	for (int i=0; i<v.size(); i++)
		m = min(m, v[i]);
	for (int i=0; i<v.size(); i++)
		v[i] = v[i]==m ? 1 : 0;
}

int main() {

//	freopen("lus.in", "rb", stdin);
	
	int z;
	scanf("%d", &z);
	while (z--) {
		int n;
		scanf("%d", &n);
		
		vector<int> va, vb, vc, vd;
		
		for (int i=0; i<n; i++) {
			int a, b, c, d;
			scanf("%d%d%d%d", &a, &b, &c, &d);
			va.push_back(a);
			vb.push_back(-b);
			vc.push_back(c);
			vd.push_back(-d);
		}
		
		process(va);
		process(vb);
		process(vc);
		process(vd);
		
		bool has_major = false;
		for (int i=0; i<n; i++)
			has_major |= va[i] + vb[i] + vc[i] + vd[i] == 4;
			
		puts(has_major ? "TAK" : "NIE");
	}
	
	return 0;
}