Chotu and SupderDevice

4.3

3 votes
Medium
Problem

The day has come when all the great coders are going to compete one last time in IIITA programming series . As a chief guest the organizers has called "THE GREAT CHOTU" to cheer the students.

Chotu decides to distribute chocolates among the coders. Chotu has initially X chocolates and there are N coders. Being a coder himself he wants to give chocolate to every coder without wasting any chocolate, so he decides to convert X chocolates into exactly N chocolates by using his superdevice.

His device has two buttons : Red and Blue. By clicking the red button he can double the amount of chocolates and By clicking the blue button, he can decrease the amount of chocolates by 1.

You need to find the minimum number of clicks chotu has to make in order obtain exactly N chocolates?

Input
First line of input contains T the number of test cases.
Next T lines contain 2 integers each X, N.

Output
For each test case print minimum number of clicks required.

Constraints
1 <= T <= 11
1 <= X <= 10000
1 <= N <= 10000

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.

Editor Image

?