In order to solve this problem, we have to start with finding the remainder when dividing a number in the form of
11...1
The input file consists of several data sets. The first line of the input file contains the number of data sets which is a positive integer and is not bigger than 20. The following lines describe the data sets.
Each data set is described by two lines. The first line contains the integer N
For each test case, write in one line the remainder when dividing P
Input
Output
Sample Input
2
4
11
5
111
Sample Output
3
1