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
#include<cstdio>
#include<vector>
#include<algorithm>
#include<set>
#include<iostream>
#include<map>

using namespace std;

#define rep(i,n) for(int i=0; i<(int)n; i++)
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define mtup make_tuple
#define REP(x, n) for(int x = 0; x < (n); ++x)

typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpii;
typedef set<int> SI;
typedef long long LL;

#ifdef DEBUG
const bool debug = true;
#else
const bool debug = false;
#endif
int n,m,k,l,h;
const int inf = 1000 * 1000 * 1000 ;
const int MAKSN = 50 * 1000 + 13; // UZUPElnic
const int INF = 1000000001;
int x,y;
int x2,y2;
// int nrPo[MAKSN],nrPo2[MAKSN];

vector<pair< pair<int,int>,int> > posortV,posortDest;

set<pair<int,int> > s;
tuple<int,int,int,int> temp;
bool ans;

void readIn()
{
	l = scanf("%d%d",&n,&h);
	rep(i,n)
	{
		l = scanf("%d%d %d%d",&x,&y,&x2,&y2);
		temp = mtup(max(x,x2),max(y,y2),min(x,x2),min(y,y2));
		posortV.pb(mp(mp(get<0>(temp),get<1>(temp)-get<3>(temp)),i));

	}

	rep(i,n)
	{
		l = scanf("%d%d %d%d",&x,&y,&x2,&y2);
		temp = mtup(max(x,x2),max(y,y2),min(x,x2),min(y,y2));
		posortDest.pb(mp(mp(get<0>(temp),get<1>(temp)-get<3>(temp)),i));
	}
}

void zeruj()
{
	s.clear();
	posortV.clear();
	posortDest.clear();
}


void solve()
{
	ans = true;
	sort(posortV.begin(),posortV.end());
	sort(posortDest.begin(),posortDest.end());

	rep(i,n)
	{
		for(int j=i+1; j<n; j++)
		{
			if(posortV[i].st.nd + posortV[j].st.nd > h)
			{
				s.insert(mp(posortV[i].nd,posortV[j].nd));
			}
		}
	}


	rep(i,n)
	{
		for(int j=i+1; j<n; j++)
		{
			if(posortDest[i].st.nd + posortDest[j].st.nd > h && s.find(mp(posortDest[i].nd,posortDest[j].nd)) == s.end())
			{
				ans = false;
			}
		}
	}


	if(ans) printf("TAK\n");
	else printf("NIE\n");
}

int main()
{
	int tests = 0;
	l = scanf("%d",&tests);

	rep(ii,tests)
	{
		zeruj();
		readIn();
		solve();
	}

	return 0;
}