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
#include <bits/stdc++.h>
using namespace std;
const int N_MAX = 123;
const int N = 5;

bool A[N], B[N], C[N];

pair<bool, bool> A5;
pair<bool, bool> B5;
pair<bool, bool> C5;

int n;

string x;

int main() {

	ios_base::sync_with_stdio(0);

	cin >> n;

	for (int i = 1; i <= n; ++i){
		cin >> x;
		if (x[1] == 'A'){
			if ((int) x[0] - '0' < 5){
				A[(int) x[0] - '0'] = true;
			}
			else if (!A5.first){
				A5.first = true;
			}
			else{
				A5.second = true;
			}
		}
		else if (x[1] == 'B'){
			if ((int) x[0] - '0' < 5){
				B[(int) x[0] - '0'] = true;
			}
			else if (!B5.first){
				B5.first = true;
			}
			else{
				B5.second = true;
			}
		}
		else{
			if ((int) x[0] - '0' < 5){
				C[(int) x[0] - '0'] = true;
			}
			else if (!C5.first){
				C5.first = true;
			}
			else{
				C5.second = true;
			}
		}
	}

	for (int i = 1; i <= 4; ++i){
		if (!A[i] || !B[i] || !C[i]){
			cout << "NIE" << '\n';
			return 0;
		}
	}

	if (!A5.first || !A5.second){
		cout << "NIE" << '\n';
		return 0;
	}
	if (!B5.first || !B5.second){
		cout << "NIE" << '\n';
		return 0;
	}
	if (!C5.first || !C5.second){
		cout << "NIE" << '\n';
		return 0;
	}


	cout << "TAK" << '\n';

	return 0;
}