Kurt Gödel

Given a word length, a prime p, and a remainder r, find all words whose Godel number has length i and leaves remainder r mod p.

Medium6Number theoryBrute forceMathNo attempts yetTime limit10sMemory limit512 MB

Problem

Kurt Friedrich Gödel was an Austrian mathematician and philosopher. Earlier scientist philosophers such as Isaac Newton and Immanuel Kant influenced him, and he later influenced mathematicians and philosophers such as Bertrand Russell. Gödel used Gödel numbering in the proof of his incompleteness theorem, which tests the boundary of mathematics and logic themselves. That proof puts him next to Aristotle among the most important logicians in history.

Here is how Gödel numbering works. It assigns a number to every symbol. In this problem the symbols are the capital letters A to Z, mapped in order to the natural numbers 1 to 26, so A becomes 1, B becomes 2, and the last letter Z becomes 26. The word KURT then becomes the sequence (11, 21, 18, 20). The sequence is written as a product of prime powers: a sequence (a1,a2,,an)(a_1, a_2, \dots, a_n) is encoded as 2a1×3a2××pnan2^{a_1} \times 3^{a_2} \times \cdots \times p_n^{a_n}, where pip_i is the ii-th prime. The Gödel number of KURT is therefore 211×321×518×720=65207444401629269211842906484375000000000002^{11} \times 3^{21} \times 5^{18} \times 7^{20} = 6520744440162926921184290648437500000000000.

The Gödel number of a long word is very large. Your friend Albert wants to leave you a message written with Gödel numbers, but he is too lazy to write out every digit. Albert writes a Gödel number gg as a triple (,r,p)(\ell, r, p), where \ell is the length of the original word, pp is a prime, and rr is the remainder of gg divided by pp. Albert did not notice that two different words can produce the same triple. The Gödel numbers of EA and JA are 96 and 3072, yet Albert may write (2,3,31)(2, 3, 31) for both of them. Decode Albert's message.

Input

There are at most 30 test cases. Each test case is one line holding three integers separated by spaces. The first integer \ell (18)(1 \le \ell \le 8) is the length of the word. The second integer rr is the remainder of the Gödel number divided by pp. The third integer pp is the prime used in the modulo operation. 0r<p<2310 \le r < p < 2^{31} always holds. The input ends with a line holding three zeros, and that line is not a test case. A word consists only of the capital letters A to Z.

Output

Print one line for each test case. If exactly one word of length \ell produces the given triple, print that word. If two or more such words exist, print ambiguous. If no such word exists, print not a word.