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

int main()
{
  iostream::sync_with_stdio(false);
  cin.tie(NULL);

  int t;
  cin >> t;
  while (t > 0) {
    --t;

    int n;
    cin >> n;
    int wm, wM, hm, hM;
    cin >> wm >> wM >> hm >> hM;
    bool ok = true;
    for (int i = 1; i < n; ++i) {
      int w1, w2, h1, h2;
      cin >> w1 >> w2 >> h1 >> h2;
      if (wm > w1) wm = w1, ok = false;
      if (wM < w2) wM = w2, ok = false;
      if (hm > h1) hm = h1, ok = false;
      if (hM < h2) hM = h2, ok = false;
      if (w1 == wm && w2 == wM && h1 == hm && h2 == hM) ok = true;
    }
    cout << (ok ? "TAK" : "NIE") << '\n';
  }

  return 0;
}