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
//============================================================================
// Name        : kug.cpp
// Author      : Grzegorz Gajoch
// Description : Potyczki 2014 - kuglarz
//============================================================================


#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <ctype.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <cstring>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <list>

using namespace std;

#define FOR(i,a,b) for(int i = a; i <= b; ++i)
#define FORD(i,a,b) for(int i = a; i >= b; --i)
#define REP(x, n) for(int x=0; x < (n); ++x)
#define VAR(v,i) __typeof(i) v=(i)
#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();++i)
#define SIZE(n) (int)n.size()
#define ALL(c) c.begin(),c.end()
#define PB(n) push_back(n)
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<bool> VB;
#define MP make_pair
#define ST first
#define ND second
const int INF = 1000000001;

#define debug



struct thing
{
	int w1, w2, h1, h2;
	thing(int a, int b, int c, int d)
	{
		w1 = a;
		w2 = b;
		h1 = c;
		h2 = d;
	}
	void print()
	{
		printf("(%d %d %d %d)\n", w1, w2, h1, h2);
	}
};
bool comp(thing a, thing b)
{
	if (a.w1 == b.w1)
	{
		if (a.h1 == b.h1)
		{
			if (a.w2 == b.w2)
				return (a.h2 > b.h2);
			return (a.w2 > b.w2);
		}
		return (a.h1 < b.h1);
	}
	return (a.w1 < b.w1);
}
int main(int argc, char **argv)
{
	int Z;
	scanf("%d", &Z);
	while (Z--)
	{
		int n;
		scanf("%d", &n);
		thing tmp(0,0,0,0);
		vector<thing> Vec;
		REP(xx, n)
		{
			scanf("%d %d %d %d\n", &tmp.w1, &tmp.w2, &tmp.h1, &tmp.h2);
			Vec.push_back(tmp);
		}
		sort(ALL(Vec), comp);
		//for (auto x : Vec)
		// x.print();
		bool flag = true;
		thing *first = &(*Vec.begin());
		for (auto x : Vec)
		{
			if (first->w1 > x.w1 ||
				first->h1 > x.h1 ||
				first->w2 < x.w2 ||
				first->h2 < x.h2)
			{
				flag = false;
				break;
			}
		}
		if (flag)
			printf("TAK\n");
		else
			printf("NIE\n");
	}
}