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
#include <iostream>
#include <list>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <cstdio>
#include <limits.h>

using namespace std;

#ifdef _WIN32

int inp()
{
	int n = 0;
	int ch = _fgetc_nolock(stdin);
	if (ch <= ' ') ch = _fgetc_nolock(stdin);
	while (ch > ' ') {
		n = 10 * n + ch - 48;
		ch = _fgetc_nolock(stdin);
	}
	return n;
}

#elif __linux

int inp()
{
	int n = 0;
	int ch = getchar_unlocked();
	if (ch <= ' ') ch = getchar_unlocked();
	while (ch > ' ') {
		n = 10 * n + ch - 48;
		ch = getchar_unlocked();
	}
	return n;
}

#endif



void checkLimits() {
	int n;
	cin >> n;
	int minw = INT_MAX, minh = INT_MAX, maxw = INT_MIN, maxh = INT_MIN;
	int w1, w2, h1, h2;
	
	bool ok = true;

	for (int i = 0; i < n; i++) {
		w1 = inp();
		w2 = inp();
		h1 = inp();
		h2 = inp();

		if (w1 < minw) {
			minw = w1;
			ok = false;
		}
		if (w2 > maxw) {
			maxw = w2;
			ok = false;
		}
		if (h1 < minh) {
			minh = h1;
			ok = false;
		}
		if (h2 > maxh) {
			maxh = h2;
			ok = false;
		}

		if (w1 == minw &&
			w2 == maxw &&
			h1 == minh &&
			h2 == maxh) {
			ok = true;
		}
	}
	if (ok) {
		cout << "TAK" << endl;
	}
	else {
		cout << "NIE" << endl;
	}

}


int main() {

#ifdef DEBUG
	clock_t t1, t2;
	t1 = clock();
#endif

	int t;
	cin >> t;

	for (int i = 0; i < t; i++) {
		checkLimits();
	}

#ifdef DEBUG
	t2 = clock();

	float diff((float)t2 - (float)t1);
	cout << diff / CLOCKS_PER_SEC << endl;
#endif

	return 0;
}