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
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
#include <vector>
#include <queue>
#include <set>

using namespace std;
const int MAXN = 100000;
const int INF = 2000000000;

int t, n;
int a, b, c, d, a0, b0, c0, d0;
bool fail;

int main() {
    scanf("%d", &t);
    while(t--) {
        scanf("%d", &n);
        scanf("%d %d %d %d", &a0, &c0, &b0, &d0);
        fail = false;
        for(int i = 1; i < n; ++i) {
            scanf("%d %d %d %d", &a, &c, &b, &d);
            if(!(a <= a0 && b <= b0 && c >= c0 && d >= d0) &&
             !(a0 <= a && b0 <= b && c0 >= c && d0 >= d)) {
                fail = true;
            }
            if(a <= a0 && b <= b0 && c >= c0 && d >= d0) {
                fail = false;
            }
            a0 = min(a, a0);
            b0 = min(b, b0);
            c0 = max(c, c0);
            d0 = max(d, d0);
        }
        if(!fail) printf("TAK\n");
        else printf("NIE\n");
    }
    return 0;
}