Tautology

Time limit1sMemory limit128 MB

Problem

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.
  • If w is a WFF, then Nw is a WFF.
  • If 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 xKwxAwxNwCwxEwx
1 111011
1 001000
0 101110
0 000111

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.

Input

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.

Output

For each test case, output a single line containing tautology or not, as appropriate.