For a positive integer , define the function as the sum of its digits in base . Also, let be the smallest such that S^k(a) does not exceed l-1, where S^k(a) means applying the function to times.
Given , find the smallest positive integer such that L(a) = N and output its value modulo .
Each test case is given in a separate line containing three integers , , (0 \le N \le 10^5, 1 \le m \le 10^9, 2 \le l \le 10^9). The input contains several test cases, followed by a line containing 0 0 0.
For each test case, output its case number and the minimal modulo .
Example
1 5 10
2 1000 17
0 0 01 1
2 10Example 1