#include <stdio.h>
// Function to find minimum operations to make A equal to B
int minOperations(int A, int B) {
// If A is already equal to B, no operations needed
if (A == B)
return 0;
// If A is greater than B, return -1 indicating impossible
if (A > B)
return -1;
// If B is odd, subtract 1 from B and recursively call the function
// If B is even, divide B by 2 and recursively call the function
if (B % 2 == 0)
return 1 + minOperations(A, B / 2);
else
return 1 + minOperations(A, B - 1);
}
int main() {
int T;
scanf("%d", &T);
while (T--) {
int A, B;
scanf("%d %d", &A, &B);
printf("%d\n", minOperations(A, B));
}
return 0;
}