Basic Modulo

Time limit1sMemory limit128 MB

Problem

You are given two non-negative integers $p$ and $m$ written in base $b$. Write a program that computes the remainder of $p$ divided by $m$ and prints it in base $b$.

Here, the remainder of $p$ divided by $m$ is the smallest non-negative integer $k$ such that $p = a \cdot m + k$ for some integer $a$.

Input

The input consists of several test cases. Each test case is given on a single line as three integers $b$, $p$, and $m$, separated by spaces.

  • $b$ is the base, with $2 \le b \le 10$.
  • $p$ and $m$ are base-$b$ integers whose digits are all between $0$ and $b-1$.
  • $p$ has at most $1000$ digits and $m$ has at most $9$ digits.

The last line contains a single $0$, which marks the end of the input.

Output

For each test case, print the remainder of $p$ divided by $m$ in base $b$ on its own line.