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

int main()
{	
	
	 int how_many_times = 0;
	 //FILE * pFile;

	//pFile = fopen ("test.txt","r");
	//fscanf (pFile, "%d", &how_many_times);	 

	scanf ("%d",&how_many_times); 
	for(int how_many_iterator = 0; how_many_iterator < how_many_times; how_many_iterator++)
	{
		long int companies_amount = 0;
		//fscanf (pFile, "%d", &companies_amount);
		scanf ("%ld",&companies_amount);
		
		long int min_width = LONG_MAX;
		long int max_width = LONG_MIN;
		long int min_height = LONG_MAX;
		long int max_height = LONG_MIN;

		
		bool is_majorating = true;
		
		for(long int i = 0; i < companies_amount; i++)
		{
			long int min_width_candidate = 0;
			long int max_width_candidate = 0;
			long int min_height_candidate = 0;
			long int max_height_candidate = 0;

			/*
			fscanf (pFile, "%d", &min_width_candidate);
			fscanf (pFile, "%d", &max_width_candidate);
			fscanf (pFile, "%d", &min_height_candidate);
			fscanf (pFile, "%d", &max_height_candidate);
			*/
			
			scanf ("%ld",&min_width_candidate);
			scanf ("%ld",&max_width_candidate);
			scanf ("%ld",&min_height_candidate);
			scanf ("%ld",&max_height_candidate);
			

			int better_candidate_iterator = 0;
			int same_dimensions_iterator = 0;

			if(min_width_candidate <= min_width)
			{
				if(min_width_candidate < min_width)
				{
					min_width = min_width_candidate;
					better_candidate_iterator++;
				}
				else
				{
					same_dimensions_iterator++;
				}
			}
			if(max_width_candidate >= max_width)
			{			
				if(max_width_candidate > max_width)
				{
					max_width = max_width_candidate;
					better_candidate_iterator++;
				}
				else
				{
					same_dimensions_iterator++;
				}
			}
			if(min_height_candidate <= min_height)
			{			
				if(min_height_candidate < min_height)
				{
					min_height = min_height_candidate;
					better_candidate_iterator++;
				}
				else
				{
					same_dimensions_iterator++;
				}
			}
			if(max_height_candidate >= max_height)
			{
				if(max_height_candidate > max_height)
				{
					max_height = max_height_candidate;
					better_candidate_iterator++;
				}
				else
				{
					same_dimensions_iterator++;
				}
			}

			if(better_candidate_iterator > 0 )
			{
				if(better_candidate_iterator + same_dimensions_iterator < 4)
				{
					is_majorating = false;
				}
				else
				{
					is_majorating = true;
				}
			}	
			if(same_dimensions_iterator == 4)
			{
				is_majorating = true;
			}
		}
		
		if(is_majorating)
		{
			printf("TAK\n");
		}
		else
		{
			printf("NIE\n");
		}
	}

	//fclose (pFile);
	//scanf("%c");

	return 0;
}