Given a number $D$ written in base $B$, write a program that prints the remainder of $D$ divided by $B-1$.
For example:
(Here $37777777777777773_8 = 1125899906842619_{10}$ and $123456_7 = 22875_{10}$.)
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.
For each test case, print the remainder of the base-$B$ number $D$ divided by $B-1$.