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
#include <algorithm>
#include <iostream>
#include <limits>
#include <vector>
#include <cstdio>

using namespace std;

#define maxi numeric_limits<int>::max()

int n, t;
vector<int> w1s;
vector<int> w2s;
vector<int> h1s;
vector<int> h2s;

int main() {
  ios::sync_with_stdio(false);
  //  cin >> t;
  scanf("%d", &t);
  while (t--) {
    //    cin >> n;
    scanf("%d", &n);
    w1s.resize(n);
    w2s.resize(n);
    h1s.resize(n);
    h2s.resize(n);
    int wmin = maxi;
    int wmax = 0;
    int hmin = maxi;
    int hmax = 0;
    for (int i = 0; i < n; i++) {
      int w1, w2, h1, h2;
      //      cin >> w1 >> w2 >> h1 >> h2;
      scanf("%d %d %d %d", &w1, &w2, &h1, &h2);
      wmin = min(wmin, w1);
      wmax = max(wmax, w2);
      hmin = min(hmin, h1);
      hmax = max(hmax, h2);
      w1s[i] = w1;
      w2s[i] = w2;
      h1s[i] = h1;
      h2s[i] = h2;
    }
    for (int i = 0; i < n; i++) {
      if (w1s[i] <= wmin && h1s[i] <= hmin && w2s[i] >= wmax && h2s[i] >= hmax) {
        cout << "TAK" << endl;
        goto out;
      }
    }
    cout << "NIE" << endl;
  out:
    {}
  }
  return 0;
}