Base Conversion

Convert the given number written in base A into base B and print its digits separated by spaces.

Easy2MathImplementationInterviewNo attempts yetTime limit2sMemory limit256 MB

Problem

After a long stretch of work, Jeongi finished building a time machine. Curious about the future, Jeongi rode it 500 years forward. Wanting to keep programming there, Jeongi opened an online judge site to solve problems. The future world writes numbers in base AA, and Jeongi, who is used to base BB, could not solve anything. Being a strong programmer, Jeongi decided to write a program that converts a number written in base AA into base BB.

Base NN means that a single position can hold NN different digits. For example, when NN is 17, the digits available in one position are 0, 1, 2, ..., 16, which is 17 of them.

Input

The first line contains the base AA used in the future world and the base BB used by Jeongi, separated by a space. Both AA and BB are natural numbers between 2 and 30.

The second line contains mm (1m251 \le m \le 25), the number of digits in the base AA number. The third line contains those mm digits, from the highest place down, separated by spaces. Each digit is at least 0 and less than AA. The number never starts with 0.

The decimal value of the base AA number is a positive integer smaller than 2202^{20}.

Output

Print the given number converted to base BB on one line. Write each digit as a decimal integer, from the highest place down, and separate consecutive digits with a single space. Do not print a leading 0.