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
#include <stdio.h>

int _read(int *n) {
	register char c = 0;
	register int res;
	while (c != EOF && c < '0')
		c=getc_unlocked(stdin);
	(*n) = 0;
	res = 0;
	while (c >= '0' && c <= '9' ) {
		(*n)=(*n)*10 + (c-'0');
		c=getc_unlocked(stdin);
		res |= 1;
	}
	return(res);
}

typedef struct {
	int val;
	int count;
	int list[100000];
} t_list;

t_list min_w;
t_list max_w;
t_list min_h;
t_list max_h;

int check[100000];

int main() {
	int t, n, i;
	int w1, w2, h1, h2;
	int res;
	
//	scanf("%d", &t);
	_read(&t);
	while(t--) {
		min_w.count = 0;
		max_w.count = 0;
		min_h.count = 0;
		max_h.count = 0;

//		scanf("%d", &n);
		_read(&n);
		for(i=0; i<n; i++) {
//			scanf("%d %d %d %d", &w1, &w2, &h1, &h2);
			_read(&w1);
			_read(&w2);
			_read(&h1);
			_read(&h2);
			
			if(!min_w.count || w1 < min_w.val) {
				min_w.val = w1;
				min_w.list[0] = i;
				min_w.count = 1;
			} else if(w1 == min_w.val) {
				min_w.list[min_w.count] = i;
				min_w.count++;
			}
			if(!max_w.count || max_w.val < w2) {
				max_w.val = w2;
				max_w.list[0] = i;
				max_w.count = 1;
			} else if(w2 == max_w.val) {
				max_w.list[max_w.count] = i;
				max_w.count++;
			}
			if(!min_h.count || h1 < min_h.val) {
				min_h.val = h1;
				min_h.list[0] = i;
				min_h.count = 1;
			} else if(h1 == min_h.val) {
				min_h.list[min_h.count] = i;
				min_h.count++;
			}
			if(!max_h.count || max_h.val < h2) {
				max_h.val = h2;
				max_h.list[0] = i;
				max_h.count = 1;
			} else if(h2 == max_h.val) {
				max_h.list[max_h.count] = i;
				max_h.count++;
			}
		}
		res = 0;
		for(i=0; i<min_w.count; i++) {
			check[min_w.list[i]]++;
		}
		for(i=0; i<max_w.count; i++) {
			check[max_w.list[i]]++;
		}
		for(i=0; i<min_h.count; i++) {
			check[min_h.list[i]]++;
		}
		for(i=0; !res && i<max_h.count; i++) {
			check[max_h.list[i]]++;
			if(check[max_h.list[i]] == 4)
				res = 1;
		}
		if(t) {
			for(i=0; i<n; i++) {
				check[i] = 0;
			}
		}
		printf("%s\n", res ? "TAK" : "NIE");
	}
	return 0;
}