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
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <cmath>

using namespace std;

typedef vector<int> VI;
typedef long long LL;

#define REP(x, n) for(int x = 0; x < (n); ++x)
#define MP(x,y) make_pair(x,y)
#define ALL(x) (x).begin(), (x).end()
#define FT(x) (x).first
#define ST(x) (x).second
#define FOREACH(i, c) for(typeof((c.begin())) i = (c).begin() ; i != (c).end(); ++i)
#define PB(x) push_back((x))
#define SZ(x) (int)x.size()
#define LN(x) (int)(x).length()

bool dom(LL w0, LL w1, LL h0, LL h1, LL wm0, LL wm1, LL hm0, LL hm1) {
    return wm0 <= w0 && w1 <= wm1 && hm0 <= h0 && h1 <= hm1;
}

void algo() {
    int n; cin >> n;
    LL minW,maxW,minH,maxH;
    bool isSol = true;
    cin >> minW >> maxW >> minH >> maxH;
    REP(_, n-1) {
	LL w0, w1, h0, h1;
	cin >> w0 >> w1 >> h0 >> h1;
	isSol = (isSol && dom(w0,w1,h0,h1,minW,maxW,minH,maxH))
	    || dom(minW,maxW,minH,maxH,w0,w1,h0,h1);
	minW = min(minW, w0); maxW = max(maxW, w1);
	minH = min(minH, h0); maxH = max(maxH, h1);
    }
    cout << (isSol ? "TAK\n" : "NIE\n");
}

int main() {
    ios_base::sync_with_stdio(false);
    int tc; cin >> tc;
    while(tc--) algo();

    return 0;
}