You are given
N M
Find the maximum possible sum of the digits (in base ) of a positive integer in the range .
Input Specification
The first line will contain the integer
The next
Output Specification
For each query, print the maximum possible sum of the digits (in base
Sample Input
Copy
2
1 100
1 9995
Sample Output
Copy
18
35
Explanation For Sample
For the second query, the sum of digits of
Comments
In the sample case, is the first query not 99, as that sums to 18, and not 9?
EDIT: My bad, that was stupid.