Time limit: 0.3s
Memory limit: 512MB
Input:
Output:
You are given an integer and a number . We first define, for any natural number , the number
We then define the value of an integer , denoted by , by:
Task
Given and , what is the maximum value of any integer less than ? In other words, what is
Input data
The first line in the input data contains the number of test cases . The lines that follow contain the test cases we are interested in. The first line of a test case contains , the number of digits of , and . The second line of a test case contains the integer .
Output data
Output lines, the answers for the values of and you are given.
Constraints and clarifications
- Let be the sum of for all test cases in a file.
- ;
- ;
- .
# | Points | Restrictions |
---|---|---|
1 | 7 | , |
2 | 3 | , |
3 | 6 | , |
4 | 6 | |
5 | 4 | |
6 | 26 | , |
7 | 48 | No further restrictions. |
Example
stdin
2
3 0
100
18 0
998877665544332211
stdout
199
1097999999999999999
Explanation
For the first test case, the optimum is given by .
For the second test case, the optimum is given by .