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
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
using namespace std;
#define REP(i,a,b) for(int i=(a);i<=(b);++i)
#define FORI(i,n) REP(i,1,n)
#define FOR(i,n) REP(i,0,int(n)-1)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define SZ(x) int((x).size())
#define DBG(v) cerr << #v << " = " << (v) << endl;
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define SORT(X) sort(X.begin(),X.end())
#define fi first
#define se second

void test(){
  int n;
  scanf("%d",&n);
  int m1 = 1000000100;
  int m2 = 1000000100;
  int d1 = -1000000100;
  int d2 = -1000000100;
  int ans = 0;
  FOR(i,n){
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    if(a < m1) ans = 0;
    if(b > d1) ans = 0;
    if(c < m2) ans = 0;
    if(d > d2) ans = 0;
    if(a <= m1 && b >= d1 && c <= m2 && d >= d2) ans = 1;
    m1 = min(m1,a);
    d1 = max(d1,b);
    m2 = min(m2,c);
    d2 = max(d2,d);
  }
  printf( ans ? "TAK\n" : "NIE\n");
}

int main () {
  int t;
  scanf("%d",&t);
  while(t--) test();
}