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
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <list>
 
using namespace std;

int main()
{
  int t, n;
  int initialized, found;
  int w1, w2, h1, h2;
  int W1, W2, H1, H2;

  cin >> t;

  while (t > 0) {
    cin >> n;
    t--;
    initialized = false;
    while (n > 0) {
      cin >> w1 >> w2 >> h1 >> h2;
      n--;
      if (!initialized) {
        W1 = w1;
        W2 = w2;
        H1 = h1;
        H2 = h2;
        initialized = true;
        found = true;
      }
      if (w1 < W1 || w2 > W2 || h1 < H1 || h2 > H2)
        found = false;
      W1 = min(W1, w1);
      W2 = max(W2, w2);
      H1 = min(H1, h1);
      H2 = max(H2, h2);
      if (w1 == W1 && w2 == W2 && h1 == H1 && h2 == H2) 
	found = true;
    }
    cout << (found ? "TAK" : "NIE") << endl;
  }
  
  return(0);
}