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
#include<fstream>
#include<vector>
#include<sstream>
#include<iomanip>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<list>
using namespace std;

struct rect{
    int height;
    int width;
    int xstart;
    int xend;
};

int maxheight;

struct restr{
    int start;
    int end;
    int height;
    int num;
};

rect begrects[50000];
int main(int argc, char**argv)
{
 int ncases;
 int numcars;
 int num;
 int tmp = scanf("%d", &ncases);
 int height;
 for(int j = 0; j < ncases; j++){
     bool pos = true;
     list<restr> restrictions;
     tmp = scanf("%d %d", &numcars, &height);
     maxheight = 0;
     for(int i = 0; i< numcars; i++){
         int tmpx, tmpy, tmpex, tmpey;
         tmp = scanf("%d %d %d %d", &tmpx, &tmpy, &tmpex, &tmpey);
         rect cur;
         cur.height = tmpey - tmpy;
         cur.width = tmpex - tmpx;
         cur.xstart = tmpx;
         begrects[i] = cur;
         if(cur.height > maxheight){
             maxheight = cur.height;
         }
     }
     for(int i = 0; i< numcars; i++){
         int tmpx, tmpy, tmpex, tmpey;
         tmp = scanf("%d %d %d %d", &tmpx, &tmpy, &tmpex, &tmpey);
         begrects[i].xend = tmpx;
         if(begrects[i].xstart > begrects[i].xend)
         {
             begrects[i].xend = begrects[i].xstart;
             begrects[i].xstart = tmpx;
         }
     }
     if(maxheight < (height / 2)){
         printf("TAK\n");
     }
     else{
         for(int i = 0; i < numcars; i++){
             if(begrects[i].height > (height / 2)){
                restr current;
                current.start = begrects[i].xstart;
                current.end = begrects[i].xend;
                current.height = begrects[i].height;
                current.num = i;
                if (current.start > current.end);{
                    int temp = current.start;
                    current.start = current.end;
                    current.end = temp;

                }
                restrictions.push_back(current);
             }
         }
         for(int i = 0; i < numcars; i++){
             for(list<restr>::iterator it = restrictions.begin(); it != restrictions.end(); it++){
                 if((*it).height + begrects[i].height > height){
                     if((*it).start < begrects[i].xstart && (*it).end > begrects[i].xend && (*it).num != i){
                         pos = false;
                     }
                     if((*it).start > begrects[i].xstart && (*it).end < begrects[i].xend && (*it).num != i){
                         pos = false;
                     }
                 }
             }
             if(pos == false) break;
         }
         if(pos == true){
             printf("TAK\n");
         }
         else
             printf("NIE\n");
     }
 }
 return 0;
}