#include <iostream>
int main()
{
    size_t words;
    std::cin >> words;
    bool* isPalindrome = new bool[words];
    for(int i = 0; i<words; ++i)
    {
        isPalindrome[i] = true;
        size_t length;
        std::cin >> length;
        char* word = new char[length+1];
        std::cin >> word;
        if(length == 1)
        {
            isPalindrome[i] = false;
        }
        else
        {
            for(int j = 0; j<length; ++j)
            {
                if(word[j] != word[length-j-1])
                {
                    isPalindrome[i] = false;
                    break;
                }
            }
        }
    }
    std::cout << "\n\n\n";
    for(int i = 0; i< words; ++i)
    {
        std::cout << "NIE\n\0TAK\n"+isPalindrome[i]*5;
    }
}
