Remainder Calculation

Time limit1sMemory limit256 MB

Problem

Given a number $D$ written in base $B$, write a program that prints the remainder of $D$ divided by $B-1$.

For example:

  • $7829_{10} \bmod 9 = 8$
  • $37777777777777773_8 \bmod 7 = 6$
  • $123456_7 \bmod 6 = 3$

(Here $37777777777777773_8 = 1125899906842619_{10}$ and $123456_7 = 22875_{10}$.)

Input

The first line contains the number of test cases $T$ ($1 \le T \le 1000$). Each of the following $T$ lines contains a base $B$ and a non-negative base-$B$ number $D$, separated by a space ($2 \le B \le 10$). $D$ has at most 10,000,000 digits.

Output

For each test case, print the remainder of the base-$B$ number $D$ divided by $B-1$.