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

#define FOR(i, n) for(__typeof(n) i = 0; i < (n); i++)
#define FORI(k, a, b) for (int k = (a); k < (b); k++)
#define FOREACH(i, c) for(__typeof((c.begin())) i=(c).begin(); i != (c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair
#define PB push_back
#define len(a) (a).size()
#define st first
#define nd second

using namespace std;

const int INF = 1000000001;

int main() {
	ios_base::sync_with_stdio(0);
	int t, n;
    cin >> t;
    FOR(i, t) {
      cin >> n;
      int w1_min = INF, w2_max = 0, h1_min = INF, h2_max = 0;
      int w1[n], w2[n], h1[n], h2[n];
      FOR(i, n) {
        cin >> w1[i] >> w2[i] >> h1[i] >> h2[i];
        w1_min = min(w1_min, w1[i]);
        w2_max = max(w2_max, w2[i]);
        h1_min = min(h1_min, h1[i]);
        h2_max = max(h2_max, h2[i]);
      }
      bool found = false;
      FOR(i, n) {
        if (w1[i] == w1_min && w2[i] == w2_max && h1[i] == h1_min && h2[i] == h2_max) {
          cout << "TAK" << endl;
          found = true;
          break;
        }
      }
      if (!found) {
        cout << "NIE" << endl;
      }
    }
}