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
57
58
59
60
61
62
63
64
65
66
67
#include <cstdio>
#include <algorithm>
#include <vector>

using std::min;
using std::max;

int t, // cases 1..10
    n, // liczba zakładów 2..100000
    w1, w2, h1, h2; // szerokość 1 <= w1 <= w <= w2 <= 10^9, wysokość 1 <= h1 <= h <= h2 <= 10^9

int minw1, maxw2, minh1, maxh2;
const int oo = 2000000000;

std::vector<
  std::pair<
    std::pair<int, int>,
    std::pair<int, int>
  >
> V;

void init()
{
  minw1 = oo;
  maxw2 = 0;
  minh1 = oo;
  maxh2 = 0;
  V.clear();
}

void push(int a, int b, int c, int d)
{
  V.push_back(std::make_pair(std::make_pair(a,b), std::make_pair(c,d)));
}

bool find(int a, int b, int c, int d)
{
  for (unsigned int i=0; i<V.size(); i++)
  {
    if (V[i].first.first == a && V[i].first.second == b && V[i].second.first == c && V[i].second.second == d)
      return true;
  }
  return false;
}

int main()
{
  scanf("%d", &t);
  while(t--)
  {
    init();
    scanf("%d", &n);
    while(n--)
    {
      scanf("%d%d%d%d", &w1, &w2, &h1, &h2);
      push(w1, w2, h1, h2);
      minw1 = min(minw1, w1);
      maxw2 = max(maxw2, w2);
      minh1 = min(minh1, h1);
      maxh2 = max(maxh2, h2);
    }
    if (find(minw1, maxw2, minh1, maxh2))
      puts("TAK");
    else
      puts("NIE");
  }
}