B-Casting#5124

B-Casting

1 second
122.599 megabytes
Very easy

Casting around for problems leads us to combine modular arithmetic with different integer bases, particularly the problem of computing values modulo b - 1, where is the base in which the value is represented. For example,

7829_{10} \mod 9 = 8

37777777777777773_{8} \mod 7 = 6

123456_{7} \mod 6 = 3

(Note that 37777777777777773_{8} = 1125899906842619_{10} and 123456_{7} = 22875_{10})

Your job is to write a program that reads integer values in various bases and computes the remainder after dividing these values by one less than the input base.

Input

The first line contains the number of data sets (1 \le t \le 1000). Each data set should be processed identically and independently.

Each data set consists of a single line of input containing three space-separated values. The first is an integer which is the data set number. The second is an integer which is the number (2 \le b \le 10), denoting a numeric base. The third is an unsigned number , in base representation. For this problem, the number of numeric characters in will be limited to .

Output

For each data set there is a single line of output. It contains the data set number followed by a single space which is then followed by the remainder resulting from dividing by (b - 1).

Examples

Example 1

Loading
Loading