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

int main() 
{
  std::ios_base::sync_with_stdio(false);
  int t;
  long n, w1max=0, w2max=0, h1max=0, h2max=0;
  long w1maj,w2maj,h1maj,h2maj;
  long w1temp,w2temp,h1temp,h2temp;
  bool wynik,sprawdz;
  cin >> t;
  for(int i = 1; i <= t; i++)
  {
    cin >> n;
   // cout <<n <<endl;
    wynik = false ; 
    for(int j = 1; j<= n; j++)
    {
      cin >> w1temp >> w2temp >> h1temp >> h2temp;
      if(j == 1) { w1max = w1maj = w1temp; w2max = w2maj = w2temp; h1max = h1maj = h1temp; h2max = h2maj = h2temp; }
      
      sprawdz = false;
      
      if(w1temp <= w1max) { w1max = w1temp; sprawdz = true;}
      if(w2temp >= w2max) { w2max = w2temp; sprawdz = true;}
      if(h1temp <= h1max) { h1max = h1temp; sprawdz = true;}
      if(h2temp >= h2max) { h2max = h2temp; sprawdz = true;}
      
      if(sprawdz = true)
      {
	if(w1temp <= w1maj && w2temp >= w2maj && h1temp <= h1maj && h2temp >= h2maj) 
	{ 
	//  cout <<"wieksze";
	  w1maj = w1temp; w2maj = w2temp; h1maj = h1temp; h2maj = h2temp;
	}
      }
      
    //  cout <<w1temp <<" "<<w2temp<<" " << h1temp<<" " <<h2temp <<"\n";
  //    cout <<"max "<<w1max << " "<<w2max<<" " <<h1max<<" "<<h2max<<endl;
    }
    if(w1maj == w1max && w2maj == w2max && h1maj == h1max && h2max == h2maj) wynik = true;
    
    if(wynik) cout << "TAK" << endl; else cout << "NIE" << endl;
    
  }
  return 0;
}