#UnknownID30. XHXMMMlOP0xMWg#,,^?
XHXMMMlOP0xMWg#,,^?
Statement
You are given two integers and .
In one operation, you can subtract any power of from . Formally, in one operation, you can replace by for any non-negative integer .
Find the minimum number of operations required to make equal to .
Format
Input
Each test contains multiple test cases. The first line contains the number of test cases ( ). The description of the test cases follows.
The only line of each test case contains two integers and ( ).
Output
For each test case, output the minimum number of operations on a new line.
Sample
6
5 2
3 5
16 4
100 3
6492 10
10 1
2
3
1
4
21
10
相关
在下列比赛中: