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
#include<stdio.h>
#include<stdlib.h>

typedef struct element {
   struct element *next;
   struct element *prev;
   int val[4];
} el_listy;

el_listy *first;
el_listy *curr;
int size;

void clear(el_listy *lista) {
    el_listy *tmp;
    while(lista!=NULL) {
	tmp=lista->next;
	free(lista);
	lista = tmp;
    }
first=NULL;
curr=NULL;
size=0;
}

void add(int *val) {
    el_listy *wsk;
    wsk = (el_listy*)malloc(sizeof(el_listy));
    wsk->val[0] = val[0];
    wsk->val[1] = val[1];
    wsk->val[2] = val[2];
    wsk->val[3] = val[3];
    wsk->prev=curr;
    wsk->next=NULL;
    if(curr!=NULL) curr->next=wsk;
    curr=wsk;
    if(first==NULL) first=wsk;
    size++;
}

void del(el_listy *wsk) {
    el_listy *prev, *next;
    if(wsk!=NULL) {
	prev = wsk->prev;
	next = wsk->next;
	free(wsk);
	if(prev!=NULL) {
	    prev->next = next;
	} else {
	    first = next;
	}
	if(next!=NULL) {
	    next->prev = prev;
	} else {
	    curr = prev;
	}
	size--;
    }
}

void addc(int *val) {
    el_listy *wsk,*tmp;
    int dodany = 0;
    wsk = first;
    if(wsk==NULL) {
	add(val);
    } else 
    while(wsk!=NULL) {
	if(val[0]>=wsk->val[0] && val[1]<=wsk->val[1] && val[2]>=wsk->val[2] && val[3]<=wsk->val[3]) {
	    //printf("jest juz taki\n");
	    //juz jest taki 
	    return;
	} else {
	    tmp = wsk->next;
	    //czy usuwac aktualny obszar
	    if(wsk->val[0]>=val[0] && wsk->val[1]<=val[1] && wsk->val[2]>=val[2] && wsk->val[3]<=val[3]) {
		//tak
		//printf("usuwamy stary\n");
		del(wsk);
	    }
	    //printf("dodajemy\n");
	    //trzeba dodac
	    if(dodany==0) {
		add(val);
		dodany=1;
	    }
	    wsk = tmp;
	}
	//wsk = wsk->next;
    }
     
}

void show(el_listy *lista) {
el_listy *wsk;
wsk = lista;
while(wsk!=NULL) {
    printf("%d %d %d %d\n",wsk->val[0],wsk->val[1],wsk->val[2],wsk->val[3]);
    wsk=wsk->next;
}
}

main() {
int el[4],n,t;

first=NULL;
curr=NULL;
size=0;

scanf("%d",&n);
while(n--) {
scanf("%d",&t);
while(t--) {
scanf("%d %d %d %d",el,el+1,el+2,el+3);
//printf("check %d %d %d %d\n",el[0],el[1],el[2],el[3]);
addc(el);
}
//show(first);
//printf("-----------------\n");
if(size>1) {
    printf("NIE\n");
} else {
    printf("TAK\n");
}
clear(first);
}

return 0;

}