Problem C: Divisor Increment
Time Limit: 1s
There is a non-negative integer K. You are allowed to add to K any of its divisors not equal to 1 and K. The same operation can be applied to the resulting number and so on. Notice that starting from the number 4, we can reach any composite number by applying several such operations. For example, the number 24 can be reached starting from 4 using 5 operations: 4->6->8->12->18->24.
You will solve a more general problem. Given integers N and M, print the minimal number of the described operations necessary to transform N into M. Print -1 if M can't be obtained from N.
Input
Standard input will contain multiple test cases. The first line of the input is a single integer T (1 <= T <= 50) which is the number of test cases. T consecutive test cases follow.
There are two integers in one line for each case, N (4 <= N <= 10,000) and M (N <= M <= 10,000).
Output
For each test case, output one line with the minimal number of the described operations necessary to transform N into M. If M can't be obtained from N, print -1 instead.
Sample Input
4 4 24 4 576 3 5 110 110
Sample Output
5 14 -1 0