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
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include <cstdio>
#include <cstdlib>
#include <vector>



#define MAX_SIZE 100000
#define BY_WIDTH 0
#define BY_HEIGHT 1
using namespace std;

class Window
{
  public:
    int fields[4];  // 0,1 -> width; 2,3 -> height
    void read_vals();
    int smaller_than(Window w1, int width);  //0 -> widht; 1 -> height
    int bigger_than(Window w1, int width);  //0 -> widht; 1 -> height
};

//void swap_comp(Window w1, Window w2);
int lowest_size(vector <Window> &tab, int field, int size);// returns index in tab
int highest_size(vector <Window> &tab, int field, int size);// returns index in tab
int compare_fields(Window w1, Window w2);

int main(int argc, const char *argv[])
{
  int t,n;
  int hs,ws, hb, wb;
  scanf("%d",&t);
  vector <Window> companies(MAX_SIZE);
  for (int i = 0; i < t; i++)
  {
    scanf("%d",&n);
    for (int j = 0; j < n; j++)
      companies[j].read_vals();
    ws = lowest_size(companies, BY_WIDTH, n);
    hs = lowest_size(companies, BY_HEIGHT, n);
    wb = highest_size(companies, BY_WIDTH, n);
    hb = highest_size(companies, BY_HEIGHT, n);
    if ((compare_fields(companies[ws], companies[hs]) == 1) 
        && (compare_fields(companies[wb], companies[hb]) == 1) 
        && (compare_fields(companies[ws], companies[wb]) == 1))
      printf("TAK\n");
    else
      printf("NIE\n");
  }

  return 0;
}

/////////////////////////////////////////////////////////////
void Window::read_vals()
{
  scanf("%d", &(this->fields[0]));
  scanf("%d", &(this->fields[1]));
  scanf("%d", &(this->fields[2]));
  scanf("%d", &(this->fields[3]));
}

// 1 means this is smaller
// 0 meand w1 is smaller
int Window::smaller_than(Window w1, int width)
{
  if (width)
  {
    if (this->fields[0] < w1.fields[0])
      return 1;
    if (this->fields[0] == w1.fields[0])
    {
      if (this->fields[1] > w1.fields[1])
        return 1;
      else
        return 0;
    }
    return 0;
  }
  else
  {
    if (this->fields[2] < w1.fields[2])
      return 1;
    if (this->fields[2] == w1.fields[2])
      if (this->fields[3] > w1.fields[3])
        return 1;
      else
        return 0;
    return 0;
  }
}

// 1 means this is smaller
// 0 meand w1 is smaller
int Window::bigger_than(Window w1, int width)
{
  if (width)
  {
    if (this->fields[1] > w1.fields[1])
      return 1;
    if (this->fields[1] == w1.fields[1])
    {
      if (this->fields[0] < w1.fields[0])
        return 1;
      else
        return 0;
    }
    return 0;
  }
  else
  {
    if (this->fields[3] > w1.fields[3])
      return 1;
    if (this->fields[3] == w1.fields[3])
      if (this->fields[2] < w1.fields[2])
        return 1;
      else
        return 0;
    return 0;
  }
}

int lowest_size(vector <Window> & tab, int field, int size)
{
  int index = 0;
  for (int i = 1; i < size; i++)
    if (tab[i].smaller_than(tab[index], field))
      index = i;
  return index;
}

int highest_size(vector <Window> & tab, int field, int size)
{
  int index = 0;
  for (int i = 1; i < size; i++)
    if (tab[i].bigger_than(tab[index], field))
      index = i;
  return index;
}


int compare_fields(Window w1, Window w2)
{
  for (int i = 0; i < 4; i++)
  {
    if (w1.fields[i] != w2.fields[i])
      return 0;
  }
  return 1;
}