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
#if defined(EMBE_DEBUG) && !defined(NDEBUG)
#include "embe-debug.hpp"
#else
#define LOG_INDENT(...) do {} while (false)
#define LOG(...) do {} while (false)
#define DUMP(...) do {} while (false)
#endif

#include <iostream>
using namespace std;

namespace {

class Solver {
  int count[5][3] = {};

public:
  void update(char r, char d)
  {
    ++count[r - '1'][d - 'A'];
  }

  bool ok() const
  {
    for (int r = 0; r < 5; ++r) {
      for (int d = 0; d < 3; ++d) {
        int target = (r == 4 ? 2 : 1);
        if (count[r][d] < target) return false;
      }
    }
    return true;
  }
};

}

int main()
{
  iostream::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;
  Solver solver;
  for (int i = 0; i < n; ++i) {
    char r, d;
    cin >> r >> d;
    LOG(r, d);
    solver.update(r, d);
  }

  cout << (solver.ok() ? "TAK" : "NIE") << '\n';

  return 0;
}