Given a positive integer , raise each of its digits to the -th power and sum the results to get S_k(n). For example, S_2(65) = 6^2 + 5^2 = 61. Construct the sequence , S_k(n), S_k(S_k(n)), and so on.
The happiness of with respect to is the smallest number appearing in this sequence.
Each line contains a separate test case with three integers , (1 \le a, b \le 10^6), and (1 \le k \le 6).
For each test case, calculate the happiness of each integer from to (inclusive) with respect to , and print their sum.
Example 1