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
#include <cstdio>
#include <algorithm>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <cmath>
#include <map>
#include <string>
#include <set>
#include <cstring>
#include <iostream>
#include <sstream>
#include <cassert>
using namespace std;
 
#define PB push_back
#define FORE(i,t) for(typeof(t.begin())i=t.begin();i!=t.end();++i)
#define SZ(x) int((x).size())
#define REP(i,n) for(int i=0,_=(n);i<_;++i)
#define FOR(i,a,b) for(int i=(a),_=(b);i<=_;++i)
#define FORD(i,a,b) for(int i=(a),_=(b);i>=_;--i)

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int INF = 1e9 + 9;

void inline jeden() {
  int n;
  scanf("%d", &n);
  vector<pair<pii, pii> > rectangles;
  int min_x = INF, max_x = -1, min_y = INF, max_y = -1;
  REP (i, n) {
    int x1, y1, x2, y2;
    scanf("%d%d%d%d", &x1, &x2, &y1, &y2);
    rectangles.PB(make_pair(pii(x1, y1), pii(x2, y2)));
    min_x = min(min_x, x1);
    max_x = max(max_x, x2);
    min_y = min(min_y, y1);
    max_y = max(max_y, y2);
  }
  auto maximal = make_pair(pii(min_x, min_y), pii(max_x, max_y));
  bool any_maximal = false;
  FORE (r, rectangles) {
    if (*r == maximal) {
      any_maximal = true;
      break;
    }
  }
  puts(any_maximal ? "TAK" : "NIE");
}

int main() {
  int z; scanf("%d", &z); while(z--)
  jeden();
}