Divisors

No attempts yetTime limit2sMemory limit512 MB

Problem

We are interested in the divisors of a given natural number nn. Let D(n)D(n) denote the set of all divisors of nn. We are given an expression built from constants taken from D(n)D(n), variables that may take any value in D(n)D(n), and two binary functions that compute the greatest common divisor and the least common multiple.

For a given expression, decide whether its value is the same for every possible assignment of values to the variables, that is, whether the expression denotes a constant function.

Input

The first line contains an integer tt (1t10001 \le t \le 1000), the number of test cases. Each of the next tt lines describes one test case.

Each description starts with an integer nn (1n10181 \le n \le 10^{18}), followed by the description of the expression. An expression is a constant, a variable, or a function application.

  • Each number is a constant and is a positive divisor of nn.
  • A variable is a sequence of at most 55 lowercase English letters; identical sequences denote the same variable.
  • The names NWD and NWW denote the functions computing the greatest common divisor and the least common multiple, respectively. A function name is followed by a single space and then the space-separated descriptions of its two arguments, each of which is itself an expression (so the description is recursive).

The total size of the input does not exceed 22 MB.

Output

Print tt lines, one answer per test case. For each test case print TAK (Polish for yes) if the expression denotes a constant function regardless of the variable values, and NIE (Polish for no) otherwise.