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
#include <cstdio>
#include <vector>
struct point{
	int x,y;
	point(int x, int y){
		this->x = x;
		this->y = y;
	}
	point(){}
};
point tab[2138];
std::vector<std::vector<int>> lista;
int maxsize = 4;
int maxdlugosc = 10;
void dfs(int depth,std::vector<int> v){
	if(depth>maxsize){
		lista.push_back(v);
	}
	else{
		for(int i=1; i<maxdlugosc; i++){
			std::vector<int> v2 = v;
			v2.push_back(i);
			dfs(depth+1,v2);
		}
	}
}
bool bylo[2000][2000];
bool check(int n,std::vector<int> v){
	int maxx =0, maxy= 0;
	int minx =1000000000, miny= 1000000000;

	bool dasie = 1;

	for(int i=0; i<n; i++){

		if(dasie == 0) break;
		for(int ix=tab[i].x; ix<v[i]+tab[i].x; ix++){
			if(dasie == 0) break;

			maxx = std::max(maxx, ix);
			minx = std::min(minx, ix);

			for(int jy = tab[i].y; jy<v[i]+tab[i].y; jy++){
				maxy = std::max(maxy, jy);
				miny = std::min(miny, jy);
				/*
				if(v.size()==4){
					if(v[0]==1 && v[1]==1 && v[2]==1 && v[3]==3 ){
						printf("%d %d\n",ix,jy);
					}
				}*/
				if(bylo[ix][jy]){
					dasie = 0;
					break;
				}
				else{
					bylo[ix][jy] = true;
				}
			}
		}
	}
	/*
	if(v.size()==4){
		if(v[0]==1 && v[1]==1 && v[2]==1 && v[3]==3 ){
			printf("n: %d\n",n);
		}
	}*/
	for(int i=minx; i<=maxx; i++){
		for(int j=miny; j<=maxy; j++){
			/*
			if(v.size()==4){
				if(v[0]==1 && v[1]==1 && v[2]==1 && v[3]==3 ){
					printf("%d ",int(bylo[i][j]));
				}
			}*/

			if(bylo[i][j]==0){
				dasie = 0;
			}
			bylo[i][j]=0;
		}
			/*if(v[0]==1 && v[1]==1 && v[2]==1 && v[3]==3 ){
					printf("\n");
				}*/
	}
	return dasie;
}
int main(){
	/*

	}*/
	int t;
	scanf("%d",&t);
	while(t--){
		lista.clear();
		int n;

		scanf("%d",&n);
		maxsize = n-1;
		for(int i=0; i<n; i++){
			int x,y;
			scanf("%d%d",&x,&y);
			tab[i] = point(x,y);
		}
		std::vector<int> vtemp;
		dfs(0,vtemp);
		bool found = false;
		for(int i=0; i<lista.size(); i++){
			if(check(n,lista[i])){
				found = true;
				printf("TAK ");
				for(int j=0; j<lista[i].size(); j++){
					printf("%d ",lista[i][j]);
				}
				printf("\n");
				break;
			}
		}
		/*for(int i=0; i<lista.size(); i++){
		for(int j=0; j<lista[i].size(); j++){
			printf("%d ",lista[i][j]);
		}printf("\n");}
		*/
		if(!found){
			printf("NIE\n");
		}
	}
}