QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 64 MB Total points: 100

#12096. Divisors

Statistics

In this problem we are interested in the divisors of a given natural number n. Let us denote the set of all these divisors by D(n). We are given an expression which consists of constant numbers from the set D(n), variables which can assume any values from the set D(n) and binary functions computing the greatest common divisor and the least common multiple.

For a given expression we would like to find out whether its value is constant regardless of the values of all variables.

Input Format

The first line of the standard input contains one integer t (1 ≤ t ≤ 1,000) denoting the number of test cases. Each of the following t lines contains a description of a single test case. Each such description starts with an integer n_{i} (1 ≤ n_{i} ≤ 10^{18}). It is followed by a description of the expression. An expression is a constant, a variable or a function.

Each number in the description represents a constant. All these numbers are positive divisors of n_{i}.

Variables are represented as sequences of at most 5 lowercase letters of the English alphabet. Variables represented by the same sequences of letters are considered the same.

The sequences of letters NWD and NWW represent the functions computing the greatest common divisor and the least common multiple, respectively. The name of a function is followed by a single space, followed by space-separated descriptions of its arguments, which are expressions (hence, the description of the expression is recursive).

You may assume that the total size of the input file does not exceed 2 MB.

Output Format

Your program should output t lines to the standard output containing the answers to subsequent test cases. The answer to a single test case is one word: TAK (meaning $ yes $ in Polish) or NIE (meaning $ no $ in Polish) stating whether the expression in the test case represents a constant function.

Example

Input

3
24 NWD 3 NWW x 12
15 NWD 15 nwd
10 10

Output

TAK
NIE
TAK

Discussions

About Discussions

The discussion section is only for posting: Editorials, General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues. Submitting multiple issues may cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.