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

typedef struct {
	int min, max;
} minmax_t;

typedef struct {
	minmax_t w, h;
} oferta_t;

int t, n;
oferta_t oferta[100000];
int i, j;
oferta_t majoranta;
int wynik;

#define	RELAX_INT_MIN(y, x)	do { if ((y) > (x)) (y) = (x); } while (0)
#define	RELAX_INT_MAX(y, x)	do { if ((y) < (x)) (y) = (x); } while (0)
#define	RELAX_MIN_MAX(y, x)	do { \
	RELAX_INT_MIN((y).min, (x).min); \
	RELAX_INT_MAX((y).max, (x).max); \
} while (0)
#define	RELAX(y, x)	do { \
	RELAX_MIN_MAX((y).w, (x).w); \
	RELAX_MIN_MAX((y).h, (x).h); \
} while (0)

const char *wynik2str[2] = { "NIE", "TAK" };

int main(void)
{
	scanf("%d", &t);
	for (i = 0; i < t; i++) {
		scanf("%d", &n);

		for (j = 0; j < n; j++) {
			scanf("%d%d%d%d", &oferta[j].w.min, &oferta[j].w.max, &oferta[j].h.min, &oferta[j].w.max);
		}

		memcpy(&majoranta, &oferta[0], sizeof(majoranta));;
		for (j = 1; j < n; j++) {
			RELAX(majoranta, oferta[j]);
		}

		wynik = 0;
		for (j = 0; j < n; j++) {
			if (!memcmp(&majoranta, &oferta[j], sizeof(majoranta))) {
				wynik = 1;
				break;
			}
		}

		puts(wynik2str[wynik]);
	}
	return 0;
}