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
#include <iostream>
using namespace std;

bool check(int x) {
    long int l2 = x;
    bool is = true;
    bool check2[10];

    for (int i = 0; i < 10; i++) {
        check2[i] = false;
    }

    while (true) {
        long int k = l2 % 10;
        if (!check2[k]) {
            if (k == 0 || x % k != 0) {
                is = false;
                break;
            }
            check2[k] = true;
        }

        l2 = l2 / 10;
        if (l2 == 0) {
            break;
        }
    }

    return is;
}

int main()
{
    int n;
    char str[3];
    int task[5][3];
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < 3; j++) {
            task[i][j] = 0;
        }
    }
    
    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> str[0];
        cin >> str[1];
        // cout << " 0i: " << ((int)str[0] - 49) << " 1:" << str[1] << "\n";

        int day = (int)str[0] - 49;
        int div = 0;
        switch (str[1]) {
            case 'A':
                div = 0;
                break;
            case 'B':
                div = 1;
                break;
            case 'C':
                div = 2;
                break;
        }

        task[day][div] += 1;
        // cout << "i: " << day << " j: " << div << " = " << task[day][div] << "\n";
    }
    

    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < 3; j++) {
            // cout << "i: " << i << " j: " << j << " = " << task[i][j] << "\n";
            if (i < 4 && task[i][j] < 1 || i == 4 && task[i][j] < 2) {
                cout << "NIE";
                return 0;
            }
        }
    }

    cout << "TAK";
    return 0;
}