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
#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int t;
  cin.sync_with_stdio(false);
  cin >> t;
  for (int tt = 0; tt < t; tt++) {
    int n;
    cin >> n;
    int g_minw, g_maxw, g_minh, g_maxh;
    cin >> g_minw >> g_maxw >> g_minh >> g_maxh;
    int best_minw = g_minw, best_maxw = g_maxw, best_minh = g_minh, best_maxh = g_maxh;
    for (int nn = 1; nn < n; nn++) {
      int minw, maxw, minh, maxh;
      cin >> minw >> maxw >> minh >> maxh;
      g_minw = min(g_minw, minw);
      g_maxw = max(g_maxw, maxw);
      g_minh = min(g_minh, minh);
      g_maxh = max(g_maxh, maxh);
      if (best_minw >= minw && best_maxw <= maxw && best_minh >= minh && best_maxh <= maxh) {
        best_minw = minw;
        best_maxw = maxw;
        best_minh = minh;
        best_maxh = maxh;
      }
    }
    if (best_minw == g_minw && best_maxw == g_maxw && best_minh == g_minh && best_maxh == g_maxh) {
      cout << "TAK" << endl;
    } else {
      cout << "NIE" << endl;
    }
  }

  return 0;
}