# Function to find minimum operations to make A equal to B
def min_operations(A, 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
# Initialize count of operations
operations = 0
# Continue until A becomes equal to or greater than B
while A < B:
# If B is odd, subtract 1 from B
if B % 2 == 1:
B -= 1
# Otherwise, if B is even, divide B by 2
else:
B //= 2
# Increment the count of operations
operations += 1
return operations
# Number of test cases
T = int(input("Enter the number of test cases: "))
# Iterate through each test case
for _ in range(T):
A, B = map(int, input().split())
print(min_operations(A, B))