WFF 'N PROOF is a logic game played with dice. Each die has six faces showing some subset of the symbols K, A, N, C, E, p, q, r, s, t. A well-formed formula (WFF) is any string of these symbols obeying the following rules:
p, q, r, s, and t are WFFs.w is a WFF, then Nw is a WFF.w and x are WFFs, then Kwx, Awx, Cwx, and Ewx are WFFs.The meaning of a WFF is defined as follows:
p, q, r, s, and t are logical variables that may take the value 0 (false) or 1 (true).K, A, N, C, and E mean and, or, not, implies, and equals, as defined in the truth table below.| w x | Kwx | Awx | Nw | Cwx | Ewx |
|---|---|---|---|---|---|
| 1 1 | 1 | 1 | 0 | 1 | 1 |
| 1 0 | 0 | 1 | 0 | 0 | 0 |
| 0 1 | 0 | 1 | 1 | 1 | 0 |
| 0 0 | 0 | 0 | 1 | 1 | 1 |
A tautology is a WFF that has value 1 (true) regardless of the values of its variables. For example, ApNp is a tautology because it is true regardless of the value of p. On the other hand, ApNq is not, because it has value 0 when p=0 and q=1.
Determine whether or not a given WFF is a tautology.
The input consists of several test cases. Each test case is a single line containing a WFF with no more than 100 symbols. A line containing only 0 follows the last case.
For each test case, output a single line containing tautology or not, as appropriate.