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
// Piotr Skoczylas

#include <cstdio>
//#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <complex>
#include <cmath>
#include <ctype.h>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <sstream>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef unsigned int UI;
typedef unsigned short US;
typedef void V;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<double> VD;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define pb push_back
#define st first
#define nd second
#define pf push_front
#define mp make_pair

#define SIZE(x) ((int)(x.size()))
#define FOR(x, b, e) for (int x = (b); x <= (e); ++x)
#define FORD(x, b, e) for (int x = (b); x >= (e); --x)
#define REP(x, n) for (int x = 0; x < (n); ++x)
#define FORI(x, b, d, e) for (int x = (b); x <= (d); x += (e))
#define FORL(x, b, d, e) for (int x = (b); x >= (d); x -= (e))
#define ALL(x) (x).begin(), (x).end()
#define VAR(x, n) __typeof(n) x = (n)
#define FOREACH(i, d) for(VAR(i, (d).begin()); i != (d).end(); ++i)
#define TMIN(x, y) (x) = min((x), (y))
#define TMAX(x, y) (x) = max((x), (y))
#define RE(x) scanf("%d", &(x))
#define RE2(x, y) scanf("%d%d", &(x), &(y))
#define RE3(x, y, z) scanf("%d%d%d", &(x), &(y), &(z))
#define WR(x) printf("%d\n", (x))
#define WR2(x, y) printf("%d %d\n", (x), (y))
#define WR3(x, y, z) printf("%d %d %d\n", (x), (y), (z))
#define PR(x) printf("%d ", (x))
#define LI printf("\n")
#define TESTS int (z); scanf("%d", &(z)); while((z)--)
#define TESTS2 int (z); cin >> (z); while((z)--)
#define IOS ios_base::sync_with_stdio(0)

inline bool interval(int b1, int e1, int b2, int e2) {
	if (b1 >= b2 && e1 <= e2) {
		return true;
	}

	return false;
}

bool answer() {
	int n, lowest_w, highest_w, lowest_h, highest_h;
	RE(n);
	RE2(lowest_w, highest_w);
	RE2(lowest_h, highest_h);
	int cand_w1, cand_w2, cand_h1, cand_h2;
	cand_w1 = lowest_w;
	cand_w2 = highest_w;
	cand_h1 = lowest_h;
	cand_h2 = highest_h;

	REP(i, n - 1) {
		int w1, w2, h1, h2;
		RE2(w1, w2);
		RE2(h1, h2);
		if (w1 <= cand_w1 && w2 >= cand_w2 && h1 <= cand_h1 && h2 >= cand_h2) {
			cand_w1 = w1;
			cand_w2 = w2;
			cand_h1 = h1;
			cand_h2 = h2;
		}
		
		if (w1 < lowest_w) {
			lowest_w = w1;
		}

		if (w2 > highest_w) {
			highest_w = w2;
		}

		if (h1 < lowest_h) {
			lowest_h = h1;
		}

		if (h2 > highest_h) {
			highest_h = h2;
		}
	}
	
	if (interval(lowest_w, highest_w, cand_w1, cand_w2) && interval(lowest_h, highest_h, cand_h1, cand_h2)) {
		return true;
	}

	return false;
}

int main() {
	TESTS {
		bool an = answer();
		if (an) {
			printf("TAK\n");
		} else {
			printf("NIE\n");
		}
	}
	return 0;
}