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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <iostream>
#include <algorithm>

using namespace std;

struct mirr_size_range 
{
   int minw;
   int maxw;
   int minh;
   int maxh;

   mirr_size_range& operator=(const mirr_size_range & other)
   {
      if (this != &other)
      {
         minw = other.minw;
         maxw = other.maxw;
         minh = other.minh;
         maxh = other.maxh;
      }
      return *this;
   }

   void extend(const mirr_size_range & other)
   {
       minw = min(minw, other.minw);
       maxw = max(maxw, other.maxw);
       minh = min(minh, other.minh);
       maxh = max(maxh, other.maxh);
   }

   friend bool operator<(const mirr_size_range & lhs, const mirr_size_range & rhs)
   {
      return   rhs.minw < lhs.minw && lhs.maxw < rhs.maxw &&
               rhs.minh < lhs.minh && lhs.maxh < rhs.maxh;   
   }

   friend bool operator==(const mirr_size_range & lhs, const mirr_size_range & rhs)
   {
      return   rhs.minw == lhs.minw && lhs.maxw == rhs.maxw &&
               rhs.minh == lhs.minh && lhs.maxh == rhs.maxh;   
   }

   friend istream& operator>>(istream & stream, mirr_size_range& msr)
   {
      stream >> msr.minw >> msr.maxw >> msr.minh >> msr.maxh;
      return stream;
   }

   friend ostream& operator<<(ostream& stream, const mirr_size_range & msr)
   {
      stream << msr.minw << " " << msr.maxw << " " << msr.minh << " " << msr.maxh;
      return stream;
   }
};

int main(int argc, char const *argv[])
{
   ios_base::sync_with_stdio(0);
   int t;
   cin >> t;
   for (int i = 0; i < t; ++i)
   {
      int n;
      cin >> n;
      mirr_size_range best, desired, akt;
      cin >> akt;
      best = akt;
      desired = akt;

      for (int j = 1; j < n; ++j)
      {
         cin >> akt;
         desired.extend(akt);
         if (best < akt)
            best = akt;
      }

      if (desired == best)
         cout << "TAK" << endl;
      else
         cout << "NIE" << endl;
   }
   return 0;
}