Johnny has recently found an ancient, broken computer. The machine has only one register, which allows one to put in there one variable. Then in one operation, you can shift its bits left or right by at most three positions. The right shift is forbidden if it cuts off some ones. So, in fact, in one operation, you can multiply or divide your number by $2$, $4$ or $8$, and division is only allowed if the number is divisible by the chosen divisor. 

Formally, if the register contains a positive integer $x$, in one operation it can be replaced by one of the following:   $x \cdot 2$  $x \cdot 4$  $x \cdot 8$  $x / 2$, if $x$ is divisible by $2$  $x / 4$, if $x$ is divisible by $4$  $x / 8$, if $x$ is divisible by $8$ 

For example, if $x = 6$, in one operation it can be replaced by $12$, $24$, $48$ or $3$. Value $6$ isn't divisible by $4$ or $8$, so there're only four variants of replacement.

Now Johnny wonders how many operations he needs to perform if he puts $a$ in the register and wants to get $b$ at the end.


-----Input-----

The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) — the number of test cases. The following $t$ lines contain a description of test cases.

The first and only line in each test case contains integers $a$ and $b$ ($1 \leq a, b \leq 10^{18}$) — the initial and target value of the variable, respectively.


-----Output-----

Output $t$ lines, each line should contain one integer denoting the minimum number of operations Johnny needs to perform. If Johnny cannot get $b$ at the end, then write $-1$.


-----Example-----
Input
10
10 5
11 44
17 21
1 1
96 3
2 128
1001 1100611139403776
1000000000000000000 1000000000000000000
7 1
10 8

Output
1
1
-1
0
2
2
14
0
-1
-1



-----Note-----

In the first test case, Johnny can reach $5$ from $10$ by using the shift to the right by one (i.e. divide by $2$).

In the second test case, Johnny can reach $44$ from $11$ by using the shift to the left by two (i.e. multiply by $4$).

In the third test case, it is impossible for Johnny to reach $21$ from $17$.

In the fourth test case, initial and target values are equal, so Johnny has to do $0$ operations.

In the fifth test case, Johnny can reach $3$ from $96$ by using two shifts to the right: one by $2$, and another by $3$ (i.e. divide by $4$ and by $8$).

Source: codeforces | Difficulty: EASY
Tags: Implementation


Solutions:
import math
for _ in range(int(input())):
	(aa, bb) = map(int, input().split())
	if aa != bb:
		a = max(aa, bb)
		b = min(aa, bb)
		xx = a // b
		if a % b == 0 and (xx and (not xx & xx - 1)):
			ans = 0
			ans += int(math.log(xx, 8))
			xx //= 8 ** int(math.log(xx, 8))
			ans += int(math.log(xx, 4))
			xx //= 4 ** int(math.log(xx, 4))
			ans += int(math.log(xx, 2))
			print(ans)
		else:
			print(-1)
	else:
		print(0)


from sys import stdin, stdout
T = int(stdin.readline().strip())
for caso in range(T):
	(a, b) = map(int, stdin.readline().strip().split())
	ans = 0
	while a > b:
		if a % 8 == 0 and a // 8 >= b:
			a = a // 8
			ans += 1
		elif a % 4 == 0 and a // 4 >= b:
			a = a // 4
			ans += 1
		elif a % 2 == 0 and a // 2 >= b:
			a = a // 2
			ans += 1
		else:
			break
	while a < b:
		if a * 8 <= b:
			a = a * 8
			ans += 1
		elif a * 4 <= b:
			a = a * 4
			ans += 1
		elif a * 2 <= b:
			a = a * 2
			ans += 1
		else:
			break
	if a == b:
		print(ans)
	else:
		print(-1)


import math
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	elif a > b:
		x = a / b
		if math.ceil(x) != math.floor(x):
			print(-1)
		else:
			s = 0
			while a != b:
				if a % 8 == 0 and a // 8 >= b:
					a = a // 8
					s += 1
				elif a % 4 == 0 and a // 4 >= b:
					a = a // 4
					s += 1
				elif a % 2 == 0 and a // 2 >= b:
					a = a // 2
					s += 1
				else:
					s = -1
					break
			print(s)
	elif a < b:
		x = b / a
		if math.ceil(x) != math.floor(x):
			print(-1)
		else:
			s = 0
			while a != b:
				if b % 8 == 0 and b // 8 >= a:
					b = b // 8
					s = s + 1
				elif b % 4 == 0 and b // 4 >= a:
					b = b // 4
					s += 1
				elif b % 2 == 0 and b // 2 >= a:
					b = b // 2
					s = s + 1
				else:
					s = -1
					break
			print(s)


import sys
from math import log2, floor, ceil, sqrt
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
for _ in range(int(ri())):
	(a, b) = Ri()
	cnt = 0
	if a < b:
		flag = True
		while a != b:
			if a > b:
				flag = False
				break
			a = a << 1
			cnt += 1
		if flag:
			print(ceil(cnt / 3))
		else:
			print(-1)
	else:
		flag = True
		while a != b:
			if a % 2 == 1:
				flag = False
				break
			a = a >> 1
			cnt += 1
		if flag:
			print(ceil(cnt / 3))
		else:
			print(-1)


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n == k:
		print(0)
	else:
		(ans, x1, x2) = (0, 0, 0)
		if n > k:
			x = int(math.log2(int(n / k)))
			if (n % 2 != 0 or n % k != 0) or k * 2 ** x != n:
				print(-1)
			else:
				r = int(n / k)
				x = int(math.log2(r))
				ans += int(x / 3)
				x = x - int(x / 3) * 3
				ans += int(x / 2)
				x = x - int(x / 2) * 2
				print(x + ans)
		if k > n:
			x = int(math.log2(int(k / n)))
			if k % 2 != 0 or k % n != 0 or n * 2 ** x != k:
				print(-1)
			else:
				r = int(k / n)
				x = int(math.log2(r))
				ans += int(x / 3)
				x = x - int(x / 3) * 3
				ans += int(x / 2)
				x = x - int(x / 2) * 2
				print(x + ans)


import math
for t in range(int(input())):
	(a, b) = map(int, input().split())
	num1 = min(a, b)
	num2 = max(a, b)
	count = 0
	while num1 < num2:
		num1 *= 2
		count += 1
	if num1 == num2:
		print(math.ceil(count / 3))
	else:
		print(-1)


import math
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	(a, b) = (max(a, b), min(a, b))
	if a % b != 0:
		print(-1)
	else:
		d = a // b
		c = 0
		while d != 1:
			if d % 2 == 0:
				c += 1
			else:
				break
			d //= 2
		if d != 1:
			print(-1)
		else:
			ans = c // 3
			c = c % 3
			ans += c // 2
			c = c % 2
			ans += c
			print(ans)


for T in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	else:
		if a > b:
			(a, b) = (b, a)
		if b % a == 0:
			b = b // a
			a = a // a
		c = 0
		while b % 8 == 0:
			b = b // 8
			c += 1
		if a != b:
			while b % 4 == 0:
				b = b // 4
				c += 1
		if a != b:
			while b % 2 == 0:
				b = b // 2
				c += 1
		print(c) if a == b else print(-1)


import math
for i in range(int(input())):
	(a, b) = sorted(map(int, input().split()))
	if b % a != 0:
		print(-1)
		continue
	else:
		y = b // a
		k = round(math.log2(y))
		if 2 ** k != y:
			print(-1)
			continue
		print((k + 2) // 3)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	elif a < b:
		cnt = 0
		while a <= b:
			a = a << 1
			cnt += 1
			if a == b:
				break
		if a == b:
			ans = cnt // 3
			if cnt % 3 != 0:
				ans += 1
			print(ans)
		else:
			print(-1)
	elif a > b:
		cnt = 0
		while a >= b:
			if a % 2 == 0:
				a = a >> 1
				cnt += 1
			else:
				break
			if a == b:
				break
		if a == b:
			ans = cnt // 3
			if cnt % 3 != 0:
				ans += 1
			print(ans)
		else:
			print(-1)


def main():
	for _ in range(int(input())):
		(a, b) = map(bin, map(int, input().split()))
		print((abs(len(a) - len(b)) + 2) // 3 if a.rstrip('0') == b.rstrip('0') else -1)
main()


from sys import stdin, stdout
from math import log
for t in range(int(stdin.readline().strip())):
	(a, b) = map(int, stdin.readline().strip().split())
	if a == b:
		print(0)
		continue
	if b > a:
		(a, b) = (b, a)
	if a % b:
		print(-1)
		continue
	c = a // b
	d = 0
	flag = False
	while c - 1:
		d += 1
		if c & 1:
			flag = True
			break
		c //= 2
	if flag:
		print(-1)
		continue
	if d % 3:
		print(d // 3 + 1)
	else:
		print(d // 3)


from math import log
import sys
input = sys.stdin.readline
MOD = 10 ** 9 + 7
for t in range(int(input())):
	(a, b) = map(int, input().split())
	(mini, maxi) = (min(a, b), max(a, b))
	c = maxi // mini
	if maxi % mini:
		print(-1)
	else:
		p = log(c, 2)
		if not p.is_integer() or 2 ** p != c:
			print(-1)
		else:
			p = int(p)
			print((p + 2) // 3)


for _ in ' ' * int(input()):
	(a, b) = map(int, input().split())
	k = k1 = 0
	while not a & 1:
		a >>= 1
		k += 1
	while not b & 1:
		b >>= 1
		k1 += 1
	print(-1 if a != b else (abs(k - k1) + 2) // 3)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	(b, a) = (min(a, b), max(a, b))
	bina = list(bin(a))
	binb = list(bin(b))
	total = -1
	if bina[2:len(binb)] == binb[2:] and '1' not in list(bina[len(binb):]):
		manage = len(bina) - len(binb)
		total = manage // 3
		manage = manage % 3
		total += manage // 2 + manage % 2
	print(total)


for t in range(int(input())):
	(n, m) = map(int, input().split())
	a = max(n, m)
	b = min(n, m)
	ans = 0
	if a == b:
		print(0)
		continue
	elif a % b != 0:
		print(-1)
		continue
	else:
		p = a // b
		c = 0
		while p % 2 == 0 and p != 1:
			p = p // 2
			c += 1
	if p == 1:
		s = c // 3
		if c % 3 != 0:
			s += 1
		print(s)
	else:
		print(-1)


for t in range(int(input())):
	(a, b) = map(int, input().split())
	if a < b:
		(a, b) = (b, a)
	bBin = bin(b)[2:]
	aBin = bin(a)[2:]
	rem = len(aBin) - len(bBin)
	bBin += ''.join(['0' for i in range(rem)])
	if int(aBin) ^ int(bBin) == 0:
		ans = 0
		ans += rem // 3
		rem %= 3
		ans += rem // 2
		rem %= 2
		ans += rem
		print(ans)
	else:
		print(-1)


from decimal import Decimal
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split(' '))
	a = Decimal(a)
	b = Decimal(b)
	if a > b:
		(a, b) = (b, a)
	if b % a != 0:
		print(-1)
	else:
		x = b / a
		count = 0
		for i in [8, 4, 2]:
			while x % i == 0:
				x /= i
				count += 1
				if x == 1:
					break
		print(count) if x == 1 else print(-1)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	c = 0
	x = max(a, b)
	y = min(a, b)
	while int(8 * y <= x):
		y *= 8
		c += 1
	while int(4 * y <= x):
		y *= 4
		c += 1
	while int(2 * y <= x):
		y *= 2
		c += 1
	if x != y:
		print(-1)
	else:
		print(c)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if max(a, b) % min(a, b) != 0:
		print(-1)
	else:
		x1 = min(a, b)
		x = max(a, b) // x1
		c = 0
		while x != 1:
			if x % 2 == 0:
				c += 1
				x = x // 2
			else:
				c = -1
				break
		if c >= 0:
			print(c // 3 + c % 3 // 2 + c % 3 % 2)
		else:
			print(-1)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a % 2 and b % 2 and (a != b):
		print(-1)
	else:
		(b, a) = (max(a, b), min(a, b))
		num = 0
		while a < b:
			num += 1
			if a * 8 <= b:
				a *= 8
			elif a * 4 <= b:
				a *= 4
			else:
				a *= 2
		if a == b:
			print(num)
		else:
			print(-1)


def main():
	n = int(input())
	for i in range(0, n):
		solve()

def solve():
	(a, b) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	ans = 0
	while a < b:
		a *= 2
		ans += 1
	if a == b:
		print(ans // 3 + min(ans % 3, 1))
	else:
		print(-1)
main()


import sys

def read():
	return sys.stdin.readline().strip()

def write(a):
	sys.stdout.write(a)

def lg(n):
	res = 0
	while n % 2 == 0:
		n //= 2
		res += 1
	return (res, n)

def solve(a, b):
	(a, b) = (max(a, b), min(a, b))
	(x, t1) = lg(a)
	(y, t2) = lg(b)
	if t1 != t2:
		return -1
	z = x - y
	r1 = z // 3
	z %= 3
	r2 = z // 2
	z %= 2
	return r1 + r2 + z

def bruh():
	t = int(read())
	ans = [0] * t
	for i in range(t):
		(a, b) = [int(i) for i in input().split()]
		ans[i] = solve(a, b)
	write('\n'.join(map(str, ans)))
bruh()


import sys
input = sys.stdin.readline
from collections import defaultdict as dd
t = int(input())
while t:
	(a, b) = map(int, input().split())
	cou = 0
	lol = 0
	if b >= a:
		while a != b:
			if b == a:
				break
			if b % 2 == 0:
				cou += 1
				b = b // 2
			else:
				lol = 1
				break
	else:
		while a != b:
			if b == a:
				break
			if a % 2 == 0:
				a = a // 2
				cou += 1
			else:
				lol = 1
				break
	if lol:
		print(-1)
	else:
		ans = 0
		ans += cou // 3
		cou = cou % 3
		ans += cou // 2
		cou = cou % 2
		ans += cou
		print(ans)
	t -= 1


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	co = 0
	if a % 2 != 0 and b % 2 != 0 and (a != b):
		print(-1)
	elif a > b and a % b != 0:
		print(-1)
	elif b > a and b % a != 0:
		print(-1)
	else:
		if a > b:
			re = a // b
		else:
			re = b // a
		temp = bin(re)
		if a == b:
			print(0)
		elif temp[2] == '1' and '1' not in temp[3:]:
			while re > 1:
				if re % 8 == 0:
					co += 1
					re = re // 8
				elif re % 4 == 0:
					co += 1
					re = re // 4
				else:
					co += 1
					re = re // 2
			print(co)
		else:
			print(-1)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	else:
		count = 0
		rem = None
		if a > b and a % b == 0:
			rem = a // b
		elif b > a and b % a == 0:
			rem = b // a
		if rem == None:
			print(-1)
		else:
			while rem % 8 == 0 and rem > 0:
				rem = rem // 8
				count += 1
			while rem % 4 == 0 and rem > 0:
				rem = rem // 4
				count += 1
			while rem % 2 == 0 and rem > 0:
				rem = rem // 2
				count += 1
			if rem == 1:
				print(count)
			else:
				print(-1)


def numOpsAToB(a, b):
	if a == b:
		return 0
	higher = max(a, b)
	lower = min(a, b)
	if higher % lower != 0:
		return -1
	counter = 0
	while higher != lower:
		lower *= 2
		counter += 1
		if lower > higher:
			return -1
	if counter in [1, 2, 3]:
		return 1
	return counter // 3 + counter % 3 // 2 + counter % 3 % 2 // 1
import sys
num_tests = int(input())
for i in range(num_tests):
	vals = input().split(' ')
	val_one = int(vals[0])
	val_two = int(vals[1])
	print(numOpsAToB(val_one, val_two))


import math

def solve():
	(a, b) = list(map(int, input().split()))
	if a > b:
		(a, b) = (b, a)
	c = 0
	while a < b:
		c += 1
		a <<= 1
	if a == b:
		return math.ceil(c / 3)
	return -1

def main():
	t = int(input())
	while t:
		print(solve())
		t -= 1
main()


t = int(input())
for case in range(t):
	(a, b) = list(map(int, input().split()))
	(c, d) = (a, b)
	if c < d:
		(c, d) = (d, c)
	if c % d != 0:
		print(-1)
		continue
	dif = c // d
	ans = 0
	while dif % 2 == 0:
		dif //= 2
		ans += 1
	if dif > 1:
		print(-1)
	else:
		final_ans = ans // 3 + (ans % 3 != 0)
		print(final_ans)


for _ in range(int(input())):
	ans = 0
	x = 0
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	elif a > b:
		while a != b:
			if a % 8 == 0 and a // 8 >= b:
				ans += 1
				a //= 8
			elif a % 4 == 0 and a // 4 >= b:
				ans += 1
				a //= 4
			elif a % 2 == 0 and a // 2 >= b:
				ans += 1
				a //= 2
			else:
				x = 1
				break
		if x == 0:
			print(ans)
		else:
			print(-1)
	else:
		while b != a:
			if b % 8 == 0 and b // 8 >= a:
				ans += 1
				b //= 8
			elif b % 4 == 0 and b // 4 >= a:
				ans += 1
				b //= 4
			elif b % 2 == 0 and b // 2 >= a:
				ans += 1
				b //= 2
			else:
				x = 1
				break
		if x == 0:
			print(ans)
		else:
			print(-1)


t = int(input())
for i in range(t):
	(x, y) = map(int, input().split())
	(x, y) = (min(x, y), max(x, y))
	if y % x != 0:
		print(-1)
		continue
	d = y // x
	ct = 0
	flag = 1
	while d != 1:
		if d % 8 == 0:
			d = d // 8
			ct += 1
		elif d % 4 == 0:
			d = d // 4
			ct += 1
		elif d % 2 == 0:
			d = d // 2
			ct += 1
		else:
			print(-1)
			flag = 0
			break
	if flag:
		print(ct)


t = int(input())

def divBy2(num):
	count = 0
	a = num
	while a % 2 == 0:
		count += 1
		a = a // 2
	return (count, a)
for i in range(t):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	else:
		(count_a, a) = divBy2(a)
		(count_b, b) = divBy2(b)
		ans = abs(count_a - count_b) // 3
		if (count_a - count_b) % 3 != 0:
			ans += 1
		if a == b:
			print(ans)
		else:
			print(-1)


t = int(input())
while t:
	(n, k) = map(int, input().split())
	c = 0
	f = 0
	if n < k:
		(n, k) = (k, n)
	while n != k:
		if n % 2 == 0 and n // 2 == k or (n % 4 == 0 and n // 4 == k) or (n % 8 == 0 and n // 8 == k):
			c += 1
			break
		if n % 8 == 0:
			c += 1
			n = n // 8
		elif n % 4 == 0:
			c += 1
			n = n // 4
		elif n % 2 == 0:
			c += 1
			n = n // 2
		else:
			f = 1
			break
	if f == 0:
		print(c)
	else:
		print(-1)
	t -= 1


import os
import sys, math
from io import BytesIO, IOBase

def main():
	t = int(input())
	for i in range(t):
		(a, b) = list(map(int, input().split()))
		if a >= b and a % b == 0:
			l = math.log2(a // b)
			l = int(l)
			if pow(2, l) != a // b:
				print(-1)
				continue
			ct = l // 3
			if l % 3 != 0:
				ct += 1
			print(ct)
		elif b >= a and b % a == 0:
			l = math.log2(b // a)
			l = int(l)
			if pow(2, l) != b // a:
				print(-1)
				continue
			ct = l // 3
			if l % 3 != 0:
				ct += 1
			print(ct)
		else:
			print(-1)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def helper(a, b):
	steps = 0
	if a == b:
		print(0)
		return
	elif a == 1 and b % 2 != 0:
		print(-1)
		return
	elif b == 1 and a % 2 != 0:
		print(-1)
		return
	if b > a:
		if b % a == 0:
			d = b // a
			while d != 1:
				if d % 8 == 0:
					d = d // 8
					steps += 1
				elif d % 4 == 0:
					d = d // 4
					steps += 1
				elif d % 2 == 0:
					d = d // 2
					steps += 1
				else:
					print(-1)
					return
			print(steps)
			return
		print(-1)
		return
	elif a > b:
		if a % b == 0:
			d = a // b
			while d != 1:
				if d % 8 == 0:
					d = d // 8
					steps += 1
				elif d % 4 == 0:
					d = d // 4
					steps += 1
				elif d % 2 == 0:
					d = d // 2
					steps += 1
				else:
					print(-1)
					return
			print(steps)
			return
		print(-1)
		return
	else:
		print(-1)
		return
for _ in range(int(input())):
	(a, b) = [int(x) for x in input().split()]
	helper(a, b)


for t in range(int(input())):
	(a, b) = map(int, input().split())
	if a < b:
		(a, b) = (b, a)
	if a % b != 0:
		print(-1)
		continue
	k = a // b
	n = 0
	while k != 1:
		if k % 2 == 0:
			k //= 2
			n += 1
		else:
			k = -1
			print(-1)
			break
	if k == -1:
		continue
	print((n + 2) // 3)


t = int(input())
for _ in range(t):
	(a, b) = list(map(int, input().strip().split()))
	(a, b) = (min(a, b), max(a, b))
	if b % a != 0:
		print(-1)
	else:
		cnt = 0
		while a < b:
			a *= 2
			cnt += 1
		if a > b:
			print(-1)
		else:
			result = cnt // 3
			if cnt % 3 >= 1:
				result += 1
			print(result)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
		continue
	c = 0
	if a > b:
		(a, b) = (b, a)
	if b % a != 0:
		print(-1)
	else:
		n = b // a
		while n % 8 == 0:
			c += 1
			n = n // 8
		while n % 4 == 0:
			c += 1
			n = n // 4
		while n % 2 == 0:
			c += 1
			n = n // 2
		if n != 1:
			print(-1)
		else:
			print(c)


from sys import stdin, stdout
import math
from collections import Counter, deque
L = lambda : list(map(int, stdin.readline().strip().split()))
M = lambda : map(int, stdin.readline().strip().split())
I = lambda : int(stdin.readline().strip())
IN = lambda : stdin.readline().strip()
C = lambda : stdin.readline().strip().split()
mod = 1000000007

def s(a):
	print(' '.join(list(map(str, a))))

def solve():
	(a, b) = M()
	x = max(a, b)
	y = min(a, b)
	z = x // y
	l = int(math.log2(z))
	if x % y != 0 or pow(2, l) != z:
		print(-1)
	else:
		print(math.ceil(l / 3))
for i in range(I()):
	solve()


t = int(input())
lst = [2 ** i for i in range(0, 61)]
for i in range(t):
	(a, b) = [int(x) for x in input().split()]
	if a == b:
		print(0)
	elif a < b:
		if b % a != 0:
			print(-1)
		elif b // a in lst:
			k = lst.index(b // a)
			if k % 3 == 0:
				print(k // 3)
			else:
				print(k // 3 + 1)
		else:
			print(-1)
	elif a % b != 0:
		print(-1)
	elif a // b in lst:
		k = lst.index(a // b)
		if k % 3 == 0:
			print(k // 3)
		else:
			print(k // 3 + 1)
	else:
		print(-1)


t = int(input())

def result(a, b):
	count = 0
	if a > b:
		if a % b == 0:
			x = a // b
		else:
			return -1
	elif a < b:
		if b % a == 0:
			x = b // a
		else:
			return -1
	else:
		return 0
	while x % 8 == 0:
		count += 1
		x = x // 8
	while x % 4 == 0:
		count += 1
		x = x // 4
	while x % 2 == 0:
		count += 1
		x = x // 2
	if x == 1:
		return count
	else:
		return -1
for i in range(t):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	print(result(a, b))


import math
t = int(input())
for qq in range(t):
	(a, b) = [int(i) for i in input().split()]
	if a < b:
		(a, b) = (b, a)
	k = a // b
	if a % b != 0:
		print(-1)
	else:
		log = 0
		tr = 1
		while k != 1:
			if k % 2:
				tr = 0
				break
			k //= 2
			log += 1
		if not tr:
			print(-1)
		else:
			print(log // 3 + log % 3 // 2 + log % 3 % 2)


for case in range(int(input())):
	(a, b) = [int(x) for x in input().split()]
	s = 0
	while a * 8 <= b:
		a *= 8
		s += 1
	while a * 4 <= b:
		a *= 4
		s += 1
	while a * 2 <= b:
		a *= 2
		s += 1
	while a % 8 == 0 and a // 8 >= b:
		a //= 8
		s += 1
	while a % 4 == 0 and a // 4 >= b:
		a //= 4
		s += 1
	while a % 2 == 0 and a // 2 >= b:
		a //= 2
		s += 1
	if a == b:
		print(s)
	else:
		print(-1)


n = int(input())
while n > 0:
	n -= 1
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	elif max(a, b) % min(a, b) == 0:
		if a > b:
			(a, b) = (b, a)
		s = 1
		while a * 8 < b:
			if b % 8 == 0:
				b = b // 8
			elif b % 4 == 0:
				b = b // 4
			elif b % 2 == 0:
				b = b // 2
			else:
				print(-1)
				break
			s += 1
		if a * 8 >= b:
			if b == 2 * a or b == 4 * a or b == 8 * a:
				print(s)
			else:
				print(-1)
	else:
		print(-1)


from collections import defaultdict
import math
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
t = int(input())
for _ in range(t):
	(a, b) = [int(x) for x in input().split()]
	n = a
	f = 0
	if a == b:
		print('0')
	if a > b:
		if a % 2 != 0:
			f = 1
		else:
			c = 0
			while n % 2 == 0 and n > b:
				n = n // 2
				c += 1
			if n == b:
				c8 = c // 3
				c = c % 3
				c4 = c // 2
				c = c % 2
				print(c + c4 + c8)
			else:
				f = 1
	if a < b:
		c = 0
		while n < b:
			n *= 2
			c += 1
		if n == b:
			c8 = c // 3
			c = c % 3
			c4 = c // 2
			c = c % 2
			print(c + c4 + c8)
		else:
			f = 1
	if f == 1:
		print('-1')


import math
t = int(input())
for q in range(t):
	(a, b) = list(map(int, input().split(' ')))
	n = max(a, b)
	x = min(a, b)
	if n == x:
		print(0)
	else:
		d = n // x
		r = n % x
		if r != 0 or n % 2 == 1:
			print(-1)
		else:
			log2 = int(math.log(d, 2.0))
			if 2 ** log2 == d:
				oito = log2 // 3
				log2 -= oito * 3
				quatro = log2 // 2
				log2 -= quatro * 2
				print(int(oito + quatro + log2))
			else:
				print(-1)


from sys import stdin, stdout
import bisect

def st():
	return list(stdin.readline().strip())

def inp():
	return int(stdin.readline())

def li():
	return list(map(int, stdin.readline().split()))

def mp():
	return map(int, stdin.readline().split())

def pr(n):
	stdout.write(str(n) + '\n')

def soe(limit):
	l = [1] * (limit + 1)
	prime = []
	for i in range(2, limit + 1):
		if l[i]:
			for j in range(i * i, limit + 1, i):
				l[j] = 0
	for i in range(2, limit + 1):
		if l[i]:
			prime.append(i)
	return prime

def segsoe(low, high):
	limit = int(high ** 0.5) + 1
	prime = soe(limit)
	n = high - low + 1
	l = [0] * (n + 1)
	for i in range(len(prime)):
		lowlimit = low // prime[i] * prime[i]
		if lowlimit < low:
			lowlimit += prime[i]
		if lowlimit == prime[i]:
			lowlimit += prime[i]
		for j in range(lowlimit, high + 1, prime[i]):
			l[j - low] = 1
	for i in range(low, high + 1):
		if not l[i - low]:
			if i != 1:
				print(i)

def power(a, n):
	r = 1
	while n:
		if n & 1:
			r = r * a
			n = n - 1
		else:
			a = a * a
			n = n >> 1
	return r

def solve():
	(a, b) = mp()
	x = max(a, b)
	y = min(a, b)
	if x % y != 0:
		pr('-1')
	else:
		d = x // y
		c = 0
		while d % 8 == 0:
			d //= 8
			c += 1
		while d % 4 == 0:
			d //= 4
			c += 1
		while d % 2 == 0:
			d //= 2
			c += 1
		if d != 1:
			pr('-1')
		else:
			pr(c)
for _ in range(inp()):
	solve()


import random

def brute(a, b):
	(b, a) = (max(b, a), min(b, a))
	c = 0
	while a < b:
		a = a * 8
		c += 1
	if a == b or a // 4 == b or a // 2 == b:
		return c
	else:
		return -1

def power_of_2(x):
	count = 0
	while True:
		x = x / 2
		count += 1
		if x % 2 != 0:
			break
	if x == 1:
		return count
	else:
		return -1

def break_x(x):
	count = 0
	while x != 0:
		if x >= 3:
			x = x - 3
			count += 1
		elif x == 2:
			x = x - 2
			count += 1
		elif x == 1:
			x = x - 1
			count += 1
	return count

def ans_finder(a, b):
	if a == b:
		return 0
	elif a > b:
		if a % b != 0:
			return -1
		else:
			q = a // b
			if q % 2 != 0:
				return -1
			else:
				x = power_of_2(q)
				if x == -1:
					return -1
				else:
					c = break_x(x)
					return c
	elif a < b:
		if b % a != 0:
			return -1
		else:
			q = b // a
			if q % 2 != 0:
				return -1
			else:
				x = power_of_2(q)
				if x == -1:
					return -1
				else:
					c = break_x(x)
					return c
t = int(input())
ans = []
for i in range(t):
	(a, b) = [int(i) for i in input().split()]
	ans.append(brute(a, b))
for i in ans:
	print(i)


n = int(input())

def func(n1, n2):
	steps = 0
	while n1 >= n2:
		if n2 * 8 <= n1:
			n2 *= 8
			steps += 1
		else:
			break
	while n1 >= n2:
		if n2 * 4 <= n1:
			n2 *= 4
			steps += 1
		else:
			break
	while n1 >= n2:
		if n2 * 2 <= n1:
			n2 *= 2
			steps += 1
		else:
			break
	return steps

def fact(n1, n2):
	if n1 > n2:
		quotient = n1 // n2
		while quotient % 2 == 0:
			quotient = quotient // 2
			if quotient == 1:
				return True
		return False
	else:
		(n1, n2) = (n2, n1)
		quotient = n1 // n2
		while quotient % 2 == 0:
			quotient = quotient // 2
			if quotient == 1:
				return True
		return False

def main(n1, n2):
	if n1 == n2:
		print(0)
	elif n1 % 2 == 1 and n2 % 2 == 1:
		print(-1)
	elif n1 % n2 == 0 or n2 % n1 == 0:
		if fact(n1, n2):
			if n1 > n2:
				print(func(n1, n2))
			else:
				print(func(n2, n1))
		else:
			print(-1)
	else:
		print(-1)
for _ in range(n):
	A = input().split()
	(n1, n2) = (int(A[0]), int(A[1]))
	main(n1, n2)


def func(x):
	count = 0
	for a in [8, 4, 2]:
		while x > 1 and x % a == 0:
			x = x // a
			count += 1
	if x > 1:
		return -1
	return count
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	elif a > b and a % b == 0:
		ops = a // b
		print(func(ops))
	elif a < b and b % a == 0:
		ops = b // a
		print(func(ops))
	else:
		print(-1)


ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
for _ in range(ii()):
	(a, b) = f()
	c = 0
	if a > b:
		if a % b == 0:
			n = a // b
		else:
			n = -1
	elif b % a == 0:
		n = b // a
	else:
		n = -1
	while n > 1:
		if n % 8 == 0:
			n = n // 8
			c = c + 1
		elif n % 4 == 0:
			n = n // 4
			c = c + 1
		elif n % 2 == 0:
			n = n // 2
			c = c + 1
		else:
			break
	if n == 1:
		print(c)
	else:
		print(-1)


import math

def pow2(g):
	res = 0
	while g % 2 == 0:
		g //= 2
		res += 1
	return res if g == 1 else None
T = int(input())
for _ in range(T):
	(x, y) = [int(a) for a in input().split()]
	(x2, y2) = (0, 0)
	while x % 2 == 0:
		x //= 2
		x2 += 1
	while y % 2 == 0:
		y //= 2
		y2 += 1
	if x != y:
		print(-1)
	else:
		diff = abs(x2 - y2)
		steps = diff // 3 + int(diff % 3 != 0)
		print(steps)


def div(a):
	while a % 2 == 0:
		a //= 2
	return a
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	count = 0
	if a > b:
		(a, b) = (b, a)
	x = div(a)
	y = div(b)
	if y != x:
		count = -1
	else:
		b //= a
		while b >= 8:
			b //= 8
			count += 1
		if b > 1:
			count += 1
	print(count)


t = int(input())
while t:
	t = t - 1
	(a, b) = map(int, input().split())
	ans = 0
	if a > b:
		if a % b != 0:
			print(-1)
		else:
			mm = a // b
			while mm != 1:
				if mm != 1 and mm % 2 != 0:
					ans = -1
					break
				if mm % 8 == 0:
					mm //= 8
					ans += 1
				elif mm % 4 == 0:
					mm //= 4
					ans += 1
				elif mm % 2 == 0:
					mm //= 2
					ans += 1
			print(ans)
	elif b % a != 0:
		print(-1)
	else:
		mm = b // a
		while mm != 1:
			if mm != 1 and mm % 2 != 0:
				ans = -1
				break
			if mm % 8 == 0:
				mm //= 8
				ans += 1
			elif mm % 4 == 0:
				mm //= 4
				ans += 1
			elif mm % 2 == 0:
				mm //= 2
				ans += 1
		print(ans)


t = int(input())
while t:
	t -= 1
	(zzz, yyyy) = map(int, input().split())
	if zzz > yyyy:
		(zzz, yyyy) = (yyyy, zzz)
	if yyyy % zzz == 0:
		k = yyyy // zzz
		x = 0
		y = 0
		z = 0
		f = 1
		xx = 1
		while k > 1:
			if k % 8 == 0:
				x += 1
				k = k // 8
			elif k % 4 == 0:
				y += 1
				k = k // 4
			elif k % 2 == 0:
				z += 1
				k = k // 2
			else:
				f = 0
				break
		if f:
			print(x + y + z)
		else:
			print(-1)
	else:
		print(-1)


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	a2 = 0
	b2 = 0
	while a > 1:
		if a % 2 == 0:
			a //= 2
			a2 += 1
		else:
			break
	while b > 1:
		if b % 2 == 0:
			b //= 2
			b2 += 1
		else:
			break
	if a != b:
		print(-1)
	else:
		k = abs(a2 - b2)
		print(k // 3 + k % 3 // 2 + k % 3 % 2)


from math import log2

def main():
	for t in range(int(input())):
		(a, b) = [int(j) for j in input().split()]
		(a, b) = (min(a, b), max(a, b))
		t = bin(a)[2:]
		s = bin(b)[2:]
		if s[:len(t)] == t and s.count('1') == t.count('1'):
			z = len(s) - len(t)
			ans = z // 3
			z = z % 3
			ans += z // 2
			z = z % 2
			ans += z
			print(ans)
		else:
			print(-1)
main()


t = int(input())
cases = []
for i in range(t):
	cases.append([int(i) for i in input().split()])
for case in cases:
	a = case[0]
	b = case[1]
	cnt = 0
	found_ans = False
	if a > b:
		if a % b == 0 and a // b & a // b - 1 == 0:
			x = a // b
		else:
			cnt = -1
			found_ans = True
	elif a < b:
		if b % a == 0 and b // a & b // a - 1 == 0:
			x = b // a
		else:
			cnt = -1
			found_ans = True
	else:
		found_ans = True
	if not found_ans:
		while x > 1:
			if x // 8 >= 0:
				x //= 8
			elif x // 4 >= 0:
				x //= 4
			elif x // 2 >= 0:
				x //= 2
			cnt += 1
	print(cnt)


import math
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	c = 0
	if a > b:
		(a, b) = (b, a)
	while a < b:
		a *= 2
		c += 1
	if a == b:
		print(math.ceil(c / 3))
	else:
		print(-1)


r = int(input())
for i in range(r):
	(a, b) = map(int, input().split())
	if b > a:
		(a, b) = (b, a)
	if a == b:
		nbre = 0
	else:
		nbre = -1
		if a % b == 0 and a // b % 2 == 0:
			dv = a // b
			n = 0
			while dv % 2 == 0 and dv != 1:
				dv = dv // 2
				n += 1
			if dv == 1:
				nbre = n // 3 + n % 3 // 2 + n % 3 % 2
	print(nbre)


t = int(input())

def aze(i, ii, j, jj):
	k = i
	kk = j
	while k < ii and kk < jj:
		if a[k] != b[kk]:
			return False
		k += 1
		kk += 1
	return True
for _ in range(t):
	(n, m) = map(int, input().split())
	a = [0 for i in range(60)]
	b = [0 for i in range(60)]
	i = 59
	while n > 0:
		a[i] = n % 2
		i -= 1
		n >>= 1
	i = 59
	while m > 0:
		b[i] = m % 2
		i -= 1
		m >>= 1
	i = a.index(1)
	j = b.index(1)
	ii = 59 - a[::-1].index(1)
	jj = 59 - b[::-1].index(1)
	if ii - i != jj - j:
		print(-1)
	elif aze(i, ii, j, jj):
		print(abs(i - j) // 3 + (abs(i - j) % 3 != 0))
	else:
		print(-1)


import sys

def factor(n):
	numbers = []
	d = 2
	while d * d <= n:
		if n % d == 0:
			numbers.append(d)
			n //= d
		else:
			d += 1
	if n > 1:
		numbers.append(n)
	return numbers

def gcd(a, b):
	while b and a:
		if a >= b:
			a %= b
		else:
			b %= a
	return max(a, b)
t = int(input())
for _ in range(t):
	(a, b) = map(int, sys.stdin.readline().split())
	if a == b:
		sys.stdout.write('0\n')
	else:
		k = 0
		l = max(a, b)
		f = min(a, b)
		while l % 2 == 0:
			if l == f:
				break
			l = l // 2
			k += 1
		if l == f:
			if k == 0:
				sys.stdout.write('-1\n')
			elif k <= 2:
				sys.stdout.write('1\n')
			elif k % 3 == 0:
				sys.stdout.write(str(k // 3) + '\n')
			else:
				sys.stdout.write(str(k // 3 + 1) + '\n')
		else:
			sys.stdout.write('-1\n')


def answer():
	nk = input().split()
	(n, m) = (int(nk[0]), int(nk[1]))
	ns = list(bin(n))[::-1]
	ms = list(bin(m))[::-1]
	(ncnt, mcnt) = (0, 0)
	for i in range(len(ns)):
		if ns[i] != '0':
			ncnt = i
			break
	for i in range(len(ms)):
		if ms[i] != '0':
			mcnt = i
			break
	if ns[ncnt:] != ms[mcnt:]:
		return -1
	diff = abs(ncnt - mcnt)
	return diff // 3 + diff % 3 // 2 + diff % 3 % 2 // 1
for _ in range(int(input())):
	print(answer())


def f(n):
	count = 0
	while n % 2 == 0:
		count += 1
		n = n // 2
	return (n == 1, count)
t = int(input())
for _ in range(t):
	s = input().split()
	(a, b) = (int(s[0]), int(s[1]))
	(a, b) = (max(a, b), min(a, b))
	if a % b == 0:
		x = a // b
		(flag, y) = f(x)
		if flag:
			if y % 3 == 0:
				print(y // 3)
			else:
				print(y // 3 + 1)
		else:
			print('-1')
	else:
		print('-1')


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	ops = 0
	while a < b:
		a <<= 1
		ops += 1
	if a == b:
		print((ops + 2) // 3)
	else:
		print('-1')


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
mod = 1000000007
import math
import bisect
from decimal import *
getcontext().prec = 50
abc = 'abcdefghijklmnopqrstuvwxyz'

def fn(n):
	c = -1
	while n:
		c += 1
		n //= 2
	return c

def isPowerOfTwo(n):
	if n == 0:
		return False
	while n != 1:
		if n % 2 != 0:
			return False
		n = n // 2
	return True
pi = 3.141592653589793

def main():
	for _ in range(ii()):
		(a, b) = mi()
		c = 0
		if a == b:
			print(0)
			continue
		if a < b:
			(a, b) = (b, a)
		s = bin(a)
		t = bin(b)
		s = s[2:]
		t = t[2:]
		x = s[len(t):]
		f = 0
		for i in range(len(t)):
			if s[i] != t[i]:
				f = 1
				break
		if f:
			print(-1)
			continue
		if x.count('0') != len(x):
			print(-1)
			continue
		else:
			print(int(math.ceil(len(x) / 3)))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def main():
	t = I()
	rr = []
	for _ in range(t):
		(a, b) = LI()
		if a > b:
			(a, b) = (b, a)
		if b % a != 0:
			rr.append(-1)
			continue
		r = 0
		t = b // a
		while t > 8:
			if t % 8 != 0:
				r = -1
				break
			t //= 8
			r += 1
		if r < 0 or t not in [1, 2, 4, 8]:
			rr.append(-1)
		else:
			if t > 1:
				r += 1
			rr.append(r)
	return JA(rr, '\n')
print(main())


import operator

def broken_pc_full(a, b, operands, cache, op_func, constraint_func):
	ops = []
	for i in operands:
		if constraint_func(a, b, i):
			op = 1 + broken_pc(op_func(a, i), b, operands, cache)
			ops.append(op)
	valid_ops = [op for op in ops if op != 0]
	if len(valid_ops) == 0:
		cache[a, b] = -1
	else:
		cache[a, b] = min(valid_ops)

def broken_pc(a, b, operands=[2, 4, 8], cache={}):
	if (a, b) in cache:
		return cache[a, b]
	if a == b:
		return 0
	if a > b:
		broken_pc_full(a, b, operands, cache, operator.floordiv, lambda a, b, i: a % i == 0)
	else:
		broken_pc_full(a, b, operands, cache, operator.mul, lambda a, b, i: a * i <= b)
	return cache[a, b]
n_tests = int(input())
for i in range(n_tests):
	(a, b) = map(int, input().split())
	print(broken_pc(a, b))


from math import ceil, floor, sqrt, log

def mod_expo(n, p, m):
	result = 1
	while p != 0:
		if p % 2 == 1:
			result = result * n % m
		p //= 2
		n = n * n % m
	return result

def is_prime(n):
	for i in range(2, floor(sqrt(n) + 1)):
		if n % i == 0:
			return False
	return True

def find_k(n):
	for k in range(0, ceil(n / 2) + 1):
		if is_prime(k + n):
			return k

def get_graph(n):
	k = find_k(n)
	m = n + k
	print(m)
	for i in range(1, n):
		print(i, i + 1)
	print(n, 1)
	for i in range(1, k + 1):
		print(i, i + floor(n / 2))

def alice_wins(n, k):
	if n < k:
		if n % 3 != 0:
			return True
		return False
	if alice_wins(k - 1, k):
		if (n - (k + 1)) % 3 != 0:
			return True
	elif (n - (k + 2)) % 3 != 0:
		return True
	return False

def prime_factorization(x):
	answer = []
	i = 2
	while i * i <= x:
		if x % i == 0:
			answer.append(i)
			while x % i == 0:
				x //= i
		i += 1
	if x > 1:
		answer.append(x)
	return answer

def pf(X, N):
	answer = 1
	m = pow(10, 9) + 7
	x_primes = prime_factorization(X)
	for prime in x_primes:
		power = 0
		factor = prime
		while factor <= N:
			power += N // factor
			factor *= prime
		answer *= pow(prime, power, m)
		answer %= m
	return answer

def find_ops(n):
	c = floor(n / 3)
	n -= 3 * floor(n / 3)
	b = floor(n / 2)
	n -= 2 * floor(n / 2)
	return n + b + c

def count_operations(a, b):
	if a < b:
		val = int(log(b / a, 2))
		if pow(2, val) * a == b:
			return find_ops(val)
	else:
		val = int(log(a / b, 2))
		if pow(2, val) * b == a:
			return find_ops(val)
	return -1
t = 1
t = int(input())
while t:
	t = t - 1
	(a, b) = map(int, input().split())
	print(count_operations(a, b))


for _ in range(int(input())):
	(a, b) = sorted(map(int, input().split()))[::-1]
	x = 0
	y = 0
	while a != 1 and a % 2 == 0:
		x += 1
		a //= 2
	while b != 1 and b % 2 == 0:
		y += 1
		b //= 2
	if a == b:
		print((abs(x - y) + 2) // 3)
	else:
		print(-1)


def binary(n):
	if n == 0:
		return '0'
	if n == 1:
		return '1'
	if n % 2:
		return binary(n // 2) + '1'
	else:
		return binary(n // 2) + '0'
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if b > a:
		if b % a:
			print(-1)
		else:
			x = binary(b // a)
			if len(x) - x.count('0') > 1:
				print(-1)
			else:
				y = len(x) - 1
				z = y % 3
				print(y // 3 + z // 2 + z % 2)
	elif a % b:
		print(-1)
	else:
		x = binary(a // b)
		if len(x) - x.count('0') > 1:
			print(-1)
		else:
			y = len(x) - 1
			z = y % 3
			print(y // 3 + z // 2 + z % 2)


def my_log(num):
	ans = 0
	while not num % 2:
		num //= 2
		ans += 1
	return ans if num == 1 else -1
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	(a, b) = (max(a, b), min(a, b))
	if not a % b:
		pot = my_log(a // b)
		if pot >= 0:
			ans = 0
			for val in [3, 2, 1]:
				while pot >= val:
					ans += 1
					pot -= val
			print(ans)
			continue
	print(-1)


def main():
	for _ in range(int(input())):
		(a, b) = sorted(map(int, input().split()))
		(a, b) = divmod(b, a)
		print(-1 if b or a & a - 1 else (a.bit_length() + 1) // 3)
main()


def get2(n):
	i = 0
	while n % 2 == 0:
		n //= 2
		i += 1
	return (n, i)
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	(na, ia) = get2(a)
	(nb, ib) = get2(b)
	if na != nb:
		print(-1)
	else:
		d = abs(ia - ib)
		res = d // 3
		d %= 3
		if d:
			res += 1
		print(res)


def getR(a):
	while a % 2 == 0:
		a //= 2
	return a
for _ in range(int(input())):
	(a, b) = list(map(int, input().split()))
	if a < b:
		(a, b) = (b, a)
	if getR(a) != getR(b):
		print(-1)
	else:
		res = 0
		a //= b
		while a >= 8:
			a //= 8
			res += 1
		if a > 1:
			res += 1
		print(res)


for tt in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
		continue
	flag = False
	if b < a:
		(a, b) = (b, a)
	if b % a != 0:
		print(-1)
	else:
		val = b // a
		cnt = 0
		while True:
			if val % 2 != 0:
				flag = True
				break
			else:
				val = val // 2
				cnt += 1
			if val <= 1:
				break
		if flag:
			print(-1)
		else:
			new = cnt // 3
			cnt = cnt - new * 3
			new2 = cnt // 2
			cnt = cnt - new2 * 2
			print(cnt + new + new2)


for _ in range(int(input())):
	(a, b) = sorted(map(int, input().split()))
	c = 0
	while a < b:
		a *= 8
		c += 1
	if a == b or a // 4 == b or a // 2 == b:
		print(c)
	else:
		print(-1)


import math

def power_2(a):
	count = 0
	while a % 2 ** count == 0:
		count += 1
	return count - 1
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	else:
		power_a = power_2(a)
		power_b = power_2(b)
		ra = int(a / 2 ** power_a)
		rb = int(b / 2 ** power_b)
		if power_a == power_b:
			if a == b:
				print(0)
			else:
				print(-1)
		elif ra == rb:
			print(math.ceil(abs(power_a - power_b) / 3))
		else:
			print(-1)


import sys
import math
sys.setrecursionlimit(1000000)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')
p2S = lambda x: print(*x, sep=' ')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def main():
	scccccc = II()
	for _ in range(scccccc):
		(a, b) = MI()
		if a % b != 0 and b % a != 0:
			print(-1)
			continue
		x = 0
		if a % b == 0:
			x = a // b
		elif b % a == 0:
			x = b // a
		r = 0
		while x % 2 == 0:
			x = x >> 1
			r += 1
		if x > 1:
			print(-1)
		else:
			g = 0
			g += r // 3
			r %= 3
			g += r // 2
			r %= 2
			g += r
			print(g)
main()


def counter(n):
	i = 0
	while n % 2 == 0:
		n //= 2
		i += 1
	return (n, i)
for _ in range(int(input())):
	(a, b) = [int(i) for i in input().split()]
	(np, ia) = counter(a)
	(nd, ib) = counter(b)
	if np != nd:
		print(-1)
	else:
		d = abs(ia - ib)
		ans = d // 3
		d %= 3
		ans += 1 if d else 0
		print(ans)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	n = 0
	if max(a, b) % min(a, b) == 0:
		n = max(a, b) // min(a, b)
	else:
		print(-1)
		continue
	ans = 0
	flag = 0
	while n >= 8:
		if n % 8 != 0:
			flag = 1
		n = n // 8
		ans += 1
	if flag == 1:
		print(-1)
		continue
	while n >= 4:
		if n % 4 != 0:
			flag = 1
		n = n // 4
		ans += 1
	if flag == 1:
		print(-1)
		continue
	while n >= 2:
		if n % 2 != 0:
			flag = 1
		n = n // 2
		ans += 1
	if flag == 1:
		print(-1)
		continue
	print(ans)


def main():
	t = int(input())
	for i in range(0, t):
		d = list(map(int, input().split()))
		a = max(d[0], d[1])
		b = min(d[0], d[1])
		print(check(a, b))

def check(a, b):
	if a % b == 0:
		c = a // b
		r = 0
		while c > 1:
			r += 1
			if c % 8 == 0:
				c = c // 8
			elif c % 4 == 0:
				c = c // 4
			elif c % 2 == 0:
				c = c // 2
			else:
				return -1
		return r
	else:
		return -1
main()


import math as m

def findr(num):
	while num % 2 == 0:
		num //= 2
	return num
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	(a, b) = (max(a, b), min(a, b))
	br = findr(b)
	if findr(a) != br:
		print(-1)
	else:
		ans = 0
		a /= b
		while a >= 8:
			a /= 8
			ans += 1
		if a > 1:
			ans += 1
		print(ans)


from decimal import Decimal
import math
test_cases = int(input())

def testCase():
	(a, b) = [Decimal(x) for x in input().strip().split()]

	def getR(a):
		while a % 2 == 0:
			a = a / 2
		return a
	if a > b:
		(a, b) = (b, a)
	r = getR(a)
	if getR(b) != r:
		print('-1')
		return
	ans = 0
	b = b / a
	while b >= 8:
		b = b / 8
		ans += 1
	if b > 1:
		ans += 1
	print(ans)
[testCase() for t in range(test_cases)]


import sys

def solve():
	return None

def main():
	q = []
	for line in sys.stdin.readlines():
		q.append(line)
	for i in range(len(q)):
		q[i] = q[i].rstrip().split(' ')
		q[i] = [int(x) for x in q[i]]
	for i in range(1, len(q)):
		a = max(q[i])
		b = min(q[i])
		if a == b:
			print(0)
			continue
		count = 0
		while b != a:
			if a % 2 == 0:
				a //= 2
				count += 1
			else:
				count = -1
				break
		if count != -1:
			if count % 3 == 0:
				fcount = count // 3
			else:
				fcount = count // 3 + 1
			count = fcount
		print(count)
main()


from fractions import Fraction
import sys
import bisect
import heapq
from math import *
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
mod = 1000000007

def inp():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def graph(vertex):
	return [[] for i in range(0, vertex + 1)]

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def solve():
	(a, b) = sep()
	if a == b:
		print(0)
	elif a > b:
		x = 0
		while a % 2 ** x == 0:
			x += 1
		x -= 1
		y = 0
		while b % 2 ** y == 0:
			y += 1
		y -= 1
		x = x - y
		a = a // 2 ** x
		if a != b:
			print(-1)
		else:
			a1 = x // 3
			x -= 3 * a1
			a2 = x // 2
			x -= 2 * a2
			print(a1 + a2 + x)
	else:
		(a, b) = (b, a)
		x = 0
		while a % 2 ** x == 0:
			x += 1
		x -= 1
		y = 0
		while b % 2 ** y == 0:
			y += 1
		y -= 1
		x = x - y
		a = a // 2 ** x
		if a != b:
			print(-1)
		else:
			a1 = x // 3
			x -= 3 * a1
			a2 = x // 2
			x -= 2 * a2
			print(a1 + a2 + x)
testcase(int(inp()))


n = int(input())
for i in range(0, n):
	p = input().rstrip().split(' ')
	a = int(p[0])
	b = int(p[1])
	if a == b:
		print(0)
	else:
		G = 0
		ans = 0
		if a > b:
			while a > b:
				if a % 8 == 0 and a // 8 >= b:
					a = a // 8
				elif a % 4 == 0 and a // 4 >= b:
					a = a // 4
				elif a % 2 == 0 and a // 2 >= b:
					a = a // 2
				else:
					G = 1
					break
				ans += 1
			if a == b and G == 0:
				print(ans)
			else:
				print(-1)
		else:
			while a < b:
				if a * 8 <= b:
					a = a * 8
				elif a * 4 <= b:
					a = a * 4
				elif a * 2 <= b:
					a = a * 2
				else:
					G = 1
					break
				ans += 1
			if a == b and G == 0:
				print(ans)
			else:
				print(-1)


from sys import stdin
import math

def solve():
	return

def main():
	inp = stdin.readline
	for _ in range(int(inp())):
		(a, b) = map(int, inp().split())
		(x, y) = (a, b)
		(ac, bc) = (0, 0)
		while x & 1 != 1:
			ac += 1
			x >>= 1
		while y & 1 != 1:
			bc += 1
			y >>= 1
		if x != y:
			print('-1')
			continue
		ans = int(math.ceil(abs(ac - bc) / 3))
		print(ans)
main()


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	if a < b:
		if b % a == 0:
			val = b // a
			if val % 8 == 0 or val % 4 == 0 or val % 2 == 0:
				count = 0
				while val > 0:
					val //= 2
					count += 1
				count -= 1
				ans = count // 3
				if count % 3 != 0:
					ans += 1
				if b // a == 2 ** count:
					print(ans)
				else:
					print(-1)
			else:
				print(-1)
		else:
			print(-1)
	else:
		print(0)


t = int(input())
output = []
i = 0

def multiplication(x, y, i):
	while x * 2 <= y:
		i += 1
		x = x * 2
	if x == y:
		if i % 3 == 0:
			i = i / 3
		elif (i - 1) % 3 == 0:
			i = (i - 1) / 3 + 1
		elif (i - 2) % 3 == 0:
			i = (i - 2) / 3 + 1
		output.append(int(i))
	else:
		output.append(-1)
for x in range(t):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	if a == b:
		output.append(i)
	elif a > b:
		multiplication(b, a, i)
	elif a < b:
		multiplication(a, b, i)
for x in output:
	print(x)


from sys import stdin, stdout
lis = lambda : list(map(int, input().split()))
Ma = lambda : map(int, input().split())
inte = lambda : int(input())
st = lambda : input()
import math
from collections import Counter

def Log2(x):
	return math.log10(x) / math.log10(2)

def isPowerOfTwo(n):
	return math.ceil(Log2(n)) == math.floor(Log2(n))
for i in range(int(input())):
	(a, b) = sorted(map(int, input().split()))
	x = b // a
	if b % a != 0 or pow(2, int(math.log2(x))) != x:
		print(-1)
	else:
		print(math.ceil(int(math.log2(x)) / 3))


import sys
t = int(input())
while t:
	(a, b) = map(int, sys.stdin.readline().strip().split())
	count = 0
	flag = 1
	while flag == 1 and abs(b - a) != 0:
		flag = 0
		(a, b) = sorted([a, b], reverse=True)
		if a % 8 == 0 and a // 8 >= b:
			flag = 1
			a = a // 8
			count += 1
		elif a % 4 == 0 and a // 4 >= b:
			flag = 1
			a = a // 4
			count += 1
		elif a % 2 == 0 and a // 2 >= b:
			flag = 1
			a = a // 2
			count += 1
	if b == a:
		print(count)
	else:
		print(-1)
	t -= 1


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	result = 0
	if a == b:
		print(0)
	else:
		if a > b:
			(a, b) = (b, a)
		(div, mod) = divmod(b, a)
		div = b
		if mod == 0:
			while True:
				if div <= a:
					break
				(d, e) = divmod(div, 8)
				if e == 0 and d >= a:
					result += 1
					div = d
					continue
				(res, four) = divmod(div, 4)
				if four == 0 and res >= a:
					result += 1
					div = res
					continue
				(ino, two) = divmod(div, 2)
				if two == 0 and ino >= a:
					result += 1
					div = ino
					continue
				break
			if div == a:
				print(result)
			else:
				print(-1)
		else:
			print(-1)


import math
t = int(input())
for i in range(t):
	A = list(map(int, input().split()))
	a = A[0]
	b = A[1]
	max1 = max(a, b)
	min1 = min(a, b)
	if max1 == min1:
		print(0)
	elif max1 % min1 == 0:
		val = max1 // min1
		val1 = int(math.log(val, 2))
		if math.pow(2, val1) == val:
			print(math.ceil(val1 / 3))
		else:
			print(-1)
	else:
		print(-1)


from math import ceil
for _ in range(int(input())):
	(a, b) = list(map(int, input().split()))
	bia = bin(a)[2:]
	bib = bin(b)[2:]
	aa = bia.strip('0')
	sca = len(bia) - len(aa)
	bb = bib.strip('0')
	scb = len(bib) - len(bb)
	if aa != bb:
		print(-1)
	else:
		print(ceil(abs(sca - scb) / 3))


import atexit
import io
import sys
import math
from collections import defaultdict, Counter
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	a1 = bin(a).lstrip('0b')
	b1 = bin(b).lstrip('0b')
	d = abs(len(a1) - len(b1))
	if a1.strip('0') != b1.strip('0'):
		print(-1)
	else:
		d1 = d // 3
		if d % 3 != 0:
			d1 += 1
		print(d1)


T = int(input())
while T > 0:
	T = T - 1
	(a, b) = map(int, input().split())
	if a > b:
		t = a
		a = b
		b = t
	cnt = 0
	while a * 8 <= b:
		cnt = cnt + 1
		a <<= 3
	while a * 4 <= b:
		cnt = cnt + 1
		a <<= 2
	while a * 2 <= b:
		cnt = cnt + 1
		a <<= 1
	if a == b:
		print(cnt)
	else:
		print(-1)


from collections import *
t = int(input())
for i in range(t):
	(a, b) = list(map(int, input().split()))
	ct = 0
	if a > b:
		while a % 2 == 0 and a > b:
			a //= 2
			ct += 1
		if a != b:
			print(-1)
			continue
		ans = ct // 3 + ct % 3 // 2 + ct % 3 % 2
		print(ans)
	else:
		while a < b:
			a *= 2
			ct += 1
		if a != b:
			print(-1)
			continue
		ans = ct // 3 + ct % 3 // 2 + ct % 3 % 2
		print(ans)


def op(a, b):
	c = 0
	while a > b:
		if a % 2 != 0:
			break
		a = a // 2
		c += 1
	if a == b:
		v1 = 0
		v1 += c // 3
		c = c % 3
		v1 += c // 2
		c = c % 2
		v1 += c
		print(v1)
	else:
		print(-1)

def op1(a, b):
	co = 0
	while a < b:
		a *= 2
		co += 1
	if a > b:
		print(-1)
	else:
		v1 = 0
		v1 += co // 3
		co = co % 3
		v1 += co // 2
		co = co % 2
		v1 += co
		print(v1)
for tc in range(int(input())):
	(a, b) = [int(i) for i in input().split()]
	if a == b:
		print(0)
	elif a > b:
		if a % 2 != 0:
			print(-1)
		else:
			op(a, b)
	elif b % 2 != 0:
		print(-1)
	else:
		op1(a, b)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if b > a:
		(a, b) = (b, a)
	if a % b:
		print(-1)
	elif a == b:
		print(0)
	else:
		a //= b
		count = 0
		while a % 2 == 0:
			count += 1
			a //= 2
		if a > 1:
			print(-1)
		else:
			print((count + 2) // 3)


n = int(input())
for i in range(n):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	h = min(a, b)
	k = max(a, b)
	if h == k:
		print(0)
	elif k % h != 0:
		print(-1)
	else:
		m = k // h
		s = 0
		while m > 1:
			if m % 8 == 0:
				s = s + 1
				m = m // 8
			elif m % 4 == 0:
				s = s + 1
				m = m // 4
			elif m % 2 == 0:
				s = s + 1
				m = m // 2
			else:
				s = -1
				break
		print(s)


import math

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)
t = int(input())
for _ in range(t):
	(a, b) = [int(i) for i in input().split()]
	flag = 0
	if a == b:
		print(0)
		flag = 1
	elif a > b:
		if a % b == 0:
			m = a // b
		else:
			print(-1)
			flag = 1
	elif b % a == 0:
		m = b // a
	else:
		print(-1)
		flag = 1
	if flag == 0:
		a1 = math.log(m, 2)
		a1 = int(a1)
		temp = a1 // 3
		t1 = math.pow(8, temp)
		t1 = int(t1)
		rem = a1 % 3
		f1 = 0
		if rem == 2:
			t1 = t1 * 4
			f1 = 1
		elif rem == 1:
			t1 = t1 * 2
			f1 = 1
		if t1 * a == b or t1 * b == a:
			print(temp + f1)
		else:
			print(-1)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	elif a < b:
		flag = 0
		(t1, t2, t3) = (a, a, a)
		ans = 0
		while t1 <= b or t2 <= b or t3 <= b:
			if t1 == b:
				flag = 1
				break
			elif t2 == b:
				flag = 1
				break
			elif t3 == b:
				flag = 1
				break
			elif t1 * 2 == b:
				ans += 1
				flag = 1
				break
			elif t1 * 4 == b:
				ans += 1
				flag = 1
				break
			elif t1 * 8 == b:
				ans += 1
				flag = 1
				break
			elif t2 * 2 == b:
				ans += 1
				flag = 1
				break
			elif t2 * 4 == b:
				ans += 1
				flag = 1
				break
			elif t2 * 8 == b:
				ans += 1
				flag = 1
				break
			elif t3 * 2 == b:
				ans += 1
				flag = 1
				break
			elif t3 * 4 == b:
				ans += 1
				flag = 1
				break
			elif t3 * 8 == b:
				ans += 1
				flag = 1
				break
			ans += 1
			t1 *= 2
			t2 *= 4
			t3 *= 8
		if flag == 1:
			print(ans)
		else:
			print(-1)
	else:
		flag = 0
		(t1, t2, t3) = (b, b, b)
		ans = 0
		while t1 <= a or t2 <= a or t3 <= a:
			if t1 == a:
				flag = 1
				break
			elif t2 == a:
				flag = 1
				break
			elif t3 == a:
				flag = 1
				break
			elif t1 * 2 == a:
				ans += 1
				flag = 1
				break
			elif t1 * 4 == a:
				ans += 1
				flag = 1
				break
			elif t1 * 8 == a:
				ans += 1
				flag = 1
				break
			elif t2 * 2 == a:
				ans += 1
				flag = 1
				break
			elif t2 * 4 == a:
				ans += 1
				flag = 1
				break
			elif t2 * 8 == a:
				ans += 1
				flag = 1
				break
			elif t3 * 2 == a:
				ans += 1
				flag = 1
				break
			elif t3 * 4 == a:
				ans += 1
				flag = 1
				break
			elif t3 * 8 == a:
				ans += 1
				flag = 1
				break
			ans += 1
			t1 *= 2
			t2 *= 4
			t3 *= 8
		if flag == 1:
			print(ans)
		else:
			print(-1)


from sys import stdin, stdout
from math import gcd, ceil, sqrt
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
tc = ii1()
for _ in range(tc):
	(a, b) = iia()
	if a == b:
		print(0)
	else:
		res = 0
		if a > b:
			count = 0
			while a % 2 == 0 and a > b:
				a //= 2
				count += 1
			if a == b:
				res = count // 3
				count %= 3
				res += count // 2
				count %= 2
				res += count
		else:
			count = 0
			while a < b:
				a *= 2
				count += 1
			if a == b:
				res = count // 3
				count %= 3
				res += count // 2
				count %= 2
				res += count
		if res == 0:
			print(-1)
		else:
			print(res)


t = int(input())
for _ in range(t):
	(a, b) = list(map(int, input().split()))
	(a, b) = (bin(a)[2:], bin(b)[2:])
	if a == b:
		print(0)
		continue
	if b > a:
		l = len(b) - len(a)
		e = a + '0' * l
		t = e == b
	else:
		l = len(a) - len(b)
		e = b + '0' * l
		t = e == a
	if not t:
		print(-1)
	else:
		o = 0
		for v in range(3, 0, -1):
			m = l // v
			o += m
			l -= m * v
		print(o)


rr = lambda : input().strip()
rri = lambda : int(rr())
rrm = lambda : [int(x) for x in rr().split()]
from sys import stdin, stdout

def sol():
	(a, b) = rrm()
	if a == b:
		print(0)
		return
	if a < b:
		res = 0
		while a < b:
			a *= 2
			res += 1
		if a != b:
			print(-1)
			return
		x = 0
		if res >= 3:
			x += res // 3
			res %= 3
		if res >= 2:
			x += res // 2
			res %= 2
		if res == 1:
			x += 1
		print(x)
		return
	res = 0
	(a, b) = (b, a)
	while a < b:
		a *= 2
		res += 1
	if a != b:
		print(-1)
		return
	x = 0
	if res >= 3:
		x += res // 3
		res %= 3
	if res >= 2:
		x += res // 2
		res %= 2
	if res == 1:
		x += 1
	print(x)
	return
	return
T = rri()
for t in range(1, T + 1):
	ans = sol()


def cap(a, b):
	if a == b:
		print(0)
		return
	if b > a:
		(a, b) = (b, a)
	if a % b != 0:
		print(-1)
		return
	count = 0
	k = a // b
	while k > 1:
		if k % 8 == 0:
			k //= 8
			count += 1
			continue
		elif k % 4 == 0:
			k //= 4
			count += 1
			continue
		elif k % 2 == 0:
			k //= 2
			count += 1
			continue
		else:
			print(-1)
			return
	print(count)
n = int(input())
for i in range(n):
	x = list(map(int, input().split(' ')))
	cap(x[0], x[1])


import sys

def get(a):
	while a % 2 == 0:
		a //= 2
	return a
I = sys.stdin.readline
ans = ''
for _ in range(int(I())):
	(a, b) = map(int, I().split())
	if a == b:
		ans += '0\n'
	else:
		if a > b:
			(a, b) = (b, a)
		if get(a) != get(b):
			ans += '-1\n'
		else:
			cnt = 0
			b //= a
			while b >= 8:
				cnt += 1
				b //= 8
			if b > 1:
				cnt += 1
			ans += str(cnt) + '\n'
print(ans)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if max(a, b) % min(a, b) != 0:
		print(-1)
	else:
		multiplier = max(a, b) // min(a, b)
		done = False
		for i in range(60):
			if multiplier == 2 ** i:
				done = True
				result = 0
				result += i // 3
				i %= 3
				result += i // 2
				i %= 2
				result += i
				print(result)
		if not done:
			print(-1)


import sys

def read():
	return list(map(int, sys.stdin.readline().split()))
for t in range(int(input())):
	(p, q) = read()
	a = max(p, q)
	b = min(p, q)
	count = 0
	done = 0
	while a >= b:
		if a ^ b == 0:
			done = 1
			print(count // 3 + (1 if count % 3 else 0))
			break
		count += 1
		b <<= 1
	if not done:
		print(-1)


import sys
import os
import heapq
import math
try:
	path = './file/input.txt'
	if os.path.exists(path):
		sys.stdin = open(path, 'r')
except:
	pass
t = int(input())

def printd(value):
	pass

def case():
	arr = list(map(int, input().split(' ')))
	(a, b) = (arr[0], arr[1])
	if a == b:
		print(0)
		return
	if a > b:
		(b, a) = (a, b)
	result = 0
	while a < b:
		a *= 2
		result += 1
	if a == b:
		print(int(result / 3) + (1 if result % 3 > 0 else 0))
		return
	print(-1)
for _ in range(t):
	case()


from math import sqrt, log2
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	c = max(a, b)
	d = min(a, b)
	a = c
	b = d
	if a >= b:
		if a % b == 0:
			x = a // b
			p = int(log2(x))
			if 2 ** p == x:
				n = p // 3
				p = p - 3 * n
				m = p // 2
				p = p - 2 * m
				h = p
				p = p - h
				print(n + m + h)
			else:
				print(-1)
		else:
			print(-1)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	c = bin(a).replace('0b', '')
	d = bin(b).replace('0b', '')
	e = int(c)
	f = int(d)
	if c.strip('0') != d.strip('0'):
		print('-1')
	else:
		zeros = 0
		while e != f:
			if e > f:
				e = e // 10
				zeros += 1
			else:
				f = f // 10
				zeros += 1
		step = 0
		while zeros > 0:
			if zeros >= 3:
				zeros -= 3
				step += 1
			elif zeros >= 2:
				zeros -= 2
				step += 1
			elif zeros >= 1:
				zeros -= 1
				step += 1
		print(step)


def solve(a, b):
	if a == b:
		return 0
	x = max(a, b)
	y = min(a, b)
	(q, r) = divmod(x, y)
	if r > 0:
		return -1
	power = 0
	while q % 2 == 0:
		q //= 2
		power += 1
	if power == 0 or q > 1:
		return -1
	(q, r) = divmod(power, 3)
	if r > 0:
		q += 1
	return q
tc = int(input())
while tc > 0:
	(a, b) = map(int, input().split())
	print(solve(a, b))
	tc -= 1


from collections import Counter
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def ispowerof2(num):
	if num & num - 1 == 0:
		return 1
	return 0
for i in range(int(input())):
	(a, b) = map(int, input().split())
	x = y = z = 0
	if b == a:
		print(0)
	elif b == 0:
		print(-1)
	elif b > a and b % a != 0:
		print(-1)
	elif b < a and a % b != 0:
		print(-1)
	else:
		if b > a:
			var = b // a
		else:
			var = a // b
		bi = bin(var)[2:]
		bi = list(bi[::-1])
		ans = bi.index('1')
		st = ispowerof2(var)
		if 2 ** ans != var or var % 2 != 0 or ans == 0:
			print(-1)
		elif st == 0:
			print(-1)
		else:
			x = ans // 3
			y = (ans - x * 3) // 2
			z = ans - x * 3 - y * 2
			if x + y + z == 0:
				print(-1)
			else:
				print(x + y + z)


import math as m
t = int(input())
for _ in range(t):
	(a, b) = list(map(int, input().split()))
	if a == b:
		print(0)
	else:
		c = min(a, b)
		d = max(a, b)
		e = 0
		if d % c == 0:
			b = d // c
			a = m.log2(b)
			if 2 ** int(a) == b:
				print(m.ceil(a / 3))
			else:
				print(-1)
		else:
			print(-1)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	c = 0
	while a < b:
		if a * 8 <= b:
			a = a * 8
		elif a * 4 <= b:
			a = a * 4
		elif a * 2 <= b:
			a = a * 2
		else:
			break
		c += 1
	print(c) if a == b else print(-1)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
		continue
	diffs = []
	diffs2 = []
	for i in range(61):
		if a & 1 << i:
			diffs.append(i)
		if b & 1 << i:
			diffs2.append(i)
	if len(diffs) != len(diffs2):
		print(-1)
	else:
		can = True
		for i in range(1, len(diffs)):
			if diffs[i] - diffs[i - 1] != diffs2[i] - diffs2[i - 1]:
				print(-1)
				can = False
				break
		if can:
			print((abs(diffs[0] - diffs2[0]) + 2) // 3)


def times(r):
	count = 0
	while True:
		if r >= 3:
			r -= 3
			count += 1
		elif r == 2:
			r -= 2
			count += 1
		elif r == 1:
			r -= 1
			count += 1
		if r == 0:
			return count

def power_of_two(number):
	r = 0
	while True:
		if number == pow(2, r):
			return times(r)
		elif number > pow(2, r):
			r += 1
		else:
			return 0
for _ in range(int(input())):
	(a, b) = list(map(int, input().split()))
	if a > b:
		if a % b == 0:
			if power_of_two(a // b):
				print(power_of_two(a // b))
			else:
				print(-1)
		else:
			print(-1)
	elif a == b:
		print(0)
	elif b % a == 0:
		if power_of_two(b // a):
			print(power_of_two(b // a))
		else:
			print(-1)
	else:
		print(-1)


t = int(input())
while t:
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	elif a % 2 != 0 and b % 2 != 0:
		print(-1)
	elif a > b and a % 2 != 0:
		print(-1)
	elif a < b and b % 2 != 0:
		print(-1)
	elif a > b:
		cn = 0
		while a > b:
			if a & 1:
				break
			a >>= 1
			cn += 1
		if a != b:
			print(-1)
		else:
			c3 = cn // 3
			cn %= 3
			c2 = cn // 2
			c1 = cn % 2
			print(c1 + c2 + c3)
	elif a < b:
		cn = 0
		while a < b:
			a <<= 1
			cn += 1
		if a != b:
			print(-1)
		else:
			c3 = cn // 3
			cn %= 3
			c2 = cn // 2
			c1 = cn % 2
			print(c1 + c2 + c3)
	t -= 1


import math
T = int(input())
for t in range(T):
	(a, b) = [int(_) for _ in input().split()]
	stra = format(a, '#0100b')
	strb = format(b, '#0100b')
	first_1_a = stra.find('1')
	last_1_a = stra.rfind('1')
	first_1_b = strb.find('1')
	last_1_b = strb.rfind('1')
	if stra[first_1_a:last_1_a + 1] != strb[first_1_b:last_1_b + 1]:
		print(-1)
	else:
		print(math.ceil(abs(first_1_a - first_1_b) / 3))


import math
for s in [*open(0)][1:]:
	(a, b) = map(int, s.split())
	d = math.gcd(a, b)
	a = bin(a // d)
	b = bin(b // d)
	print((-1, 0 - -abs(len(a) - len(b)) // 3)[{*a[3:]} <= {'0'} >= {*b[3:]}])


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	bb = max(a, b)
	s = min(a, b)
	c = 0
	ff = 0
	while s <= bb:
		if s == bb:
			ff = 1
			break
		else:
			if s * 8 <= bb:
				s = s * 8
			elif s * 4 <= bb:
				s = s * 4
			else:
				s = s * 2
			c = c + 1
	if ff == 1:
		print(c)
	else:
		print(-1)


for _ in range(int(input())):
	(a, b) = map(int, input().split())

	def f(a):
		count = 0
		while a % 2 == 0:
			a >>= 1
			count += 1
		return (a, count)
	(a, A) = f(a)
	(b, B) = f(b)
	if a != b:
		print(-1)
	else:
		count = abs(A - B) + 2
		print(count // 3)


for i in range(int(input())):
	(a, b) = list(map(int, input().split()))
	if a == b:
		print(0)
		continue
	if a > b:
		(a, b) = (b, a)
	nA = list(map(int, list(bin(a))[2:]))
	nB = list(map(int, list(bin(b))[2:]))
	if nA != nB[:len(nA)] or nA.count(1) != nB.count(1):
		print(-1)
	else:
		t = 0
		nM = len(nB) - len(nA)
		t += nM // 3
		nM -= nM // 3 * 3
		t += nM // 2
		nM -= nM // 2 * 2
		t += nM // 1
		nM -= nM // 1 * 1
		print(t)


import sys
import math

def get_ints():
	return map(int, input().strip().split())

def get_list():
	return list(get_ints())

def printspx(*args):
	return print(*args, end='')

def printsp(*args):
	return print(*args, end=' ')

def printchk(*args):
	return print(*args, end=' \\ ')
MODPRIME = int(1000000000.0 + 7)
BABYMODPR = 998244353
for _testcases_ in range(int(input())):
	(a, b) = get_ints()
	ans = steps = 0
	if a == b:
		ans = 0
	elif a < b:
		while a < b:
			a = a << 1
			steps += 1
		if a != b:
			ans = -1
		else:
			ans += steps // 3
			steps = steps % 3
			ans += steps // 2
			steps = steps % 2
			ans += steps
	else:
		while a > b:
			if a & 1 == 1:
				break
			else:
				a = a >> 1
				steps += 1
		if a != b:
			ans = -1
		else:
			ans += steps // 3
			steps = steps % 3
			ans += steps // 2
			steps = steps % 2
			ans += steps
	print(ans)


from math import ceil
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	i = j = 0
	(aa, bb) = (a, b)
	while bb % 2 == 0:
		bb //= 2
		j += 1
	while aa % 2 == 0:
		aa //= 2
		i += 1
	if aa != bb:
		print(-1)
		continue
	print(ceil(abs(i - j) / 3))


import math
t = int(input())
for _ in range(t):
	(a, b) = list(map(int, input().split()))
	count = 0
	if a > b:
		while a % 2 == 0 and a > b:
			count += 1
			a = a // 2
		if a == b:
			print(math.ceil(count / 3))
		else:
			print(-1)
	else:
		while b % 2 == 0 and b > a:
			count += 1
			b = b // 2
		if a == b:
			print(math.ceil(count / 3))
		else:
			print(-1)


import math
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
		continue
	c = a
	atwos = 0
	while c % 2 == 0:
		c //= 2
		atwos += 1
	d = b
	btwos = 0
	while d % 2 == 0:
		d //= 2
		btwos += 1
	if c != d:
		print(-1)
	else:
		f = abs(atwos - btwos)
		print(math.ceil(f / 3))


from sys import stdin
input = lambda : stdin.readline().strip()
from math import ceil, sqrt, factorial, gcd
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	elif a < b:
		if b % a != 0:
			print(-1)
		else:
			z = b // a
			count = 0
			while z > 1:
				if z % 8 == 0:
					z = z // 8
				elif z % 4 == 0:
					z = z // 4
				elif z % 2 == 0:
					z = z // 2
				else:
					print(-1)
					break
				count += 1
			if z == 1:
				print(count)
	else:
		count = 0
		while a != b:
			if a % 8 == 0 and a // 8 >= b:
				a = a // 8
			elif a % 4 == 0 and a // 4 >= b:
				a = a // 4
			elif a % 2 == 0 and a // 2 >= b:
				a = a // 2
			else:
				print(-1)
				break
			count += 1
		if a == b:
			print(count)


n = int(input())

def solve(a, b):
	c = 0
	if a < b:
		while a < b:
			a *= 2
			c += 1
		if a == b:
			mul8 = c // 3
			mul4 = c % 3 // 2
			mul2 = c % 3 % 2
			print(mul8 + mul4 + mul2)
		else:
			print(-1)
	elif a > b:
		while a > b and a % 2 == 0:
			a //= 2
			c += 1
		if a == b:
			mul8 = c // 3
			mul4 = c % 3 // 2
			mul2 = c % 3 % 2
			print(mul8 + mul4 + mul2)
		else:
			print(-1)
	else:
		print(0)
for i in range(n):
	(a, b) = map(int, input().split(' '))
	solve(a, b)


t = int(input())
for i in range(t):
	(a, b) = map(bin, map(int, input().split()))
	a = a[2:]
	b = b[2:]
	A = a
	B = b
	decA = 0
	decB = 0
	while len(A) and A[-1] == '0':
		A = A[:-1]
		decA += 1
	while len(B) and B[-1] == '0':
		B = B[:-1]
		decB += 1
	if A != B:
		print(-1)
	else:
		d = abs(decA - decB)
		print(d // 3 + (1 if d % 3 else 0))


from math import ceil, log
from decimal import Decimal
t = int(input())
for _ in range(t):
	(a, b) = input().split()
	(a, b) = (Decimal(a), Decimal(b))
	ar = a * 1
	while ar % 2 == 0:
		ar /= 2
	br = b * 1
	while br % 2 == 0:
		br /= 2
	res = 0
	if ar != br:
		res = -1
	else:
		r = b / a
		if a > b:
			r = a / b
		while r % 8 == 0:
			res += 1
			r /= 8
		while r % 4 == 0:
			res += 1
			r /= 4
		while r % 2 == 0:
			res += 1
			r /= 2
	print(res)


cases = int(input())
while cases:
	cases -= 1
	(num, target) = map(int, input().split())
	if num > target:
		(target, num) = (num, target)
	ans = 0
	while target != num:
		num *= 2
		ans += 1
		if num > target:
			ans = -1
			break
	if ans != -1:
		ans = ans // 3 + ans % 3 // 2 + ans % 3 % 2
	print(ans)


def solve():
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	aZero = bZero = 0
	while not a % 2:
		a >>= 1
		aZero += 1
	while not b % 2:
		b >>= 1
		bZero += 1
	if a != b:
		print(-1)
	else:
		zero = bZero - aZero
		(q, r) = divmod(zero, 3)
		print(q + 1 if r else q)
for _ in range(int(input())):
	solve()


testcase = int(input())
for test in range(testcase):
	res = 0
	(num1, num2) = map(int, input().split())
	if num1 % num2 != 0 and num2 % num1 != 0:
		res = -1
		print(res)
	else:
		if num1 > num2:
			div = num1 // num2
		else:
			div = num2 // num1
		while True:
			if div % 8 == 0:
				div = div // 8
				res += 1
				continue
			elif div % 4 == 0:
				div = div // 4
				res += 1
				continue
			elif div % 2 == 0:
				div = div // 2
				res += 1
				continue
			elif div == 1:
				break
			else:
				res = -1
				break
		print(res)


from math import gcd, log2
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	number = gcd(a, b)
	a //= number
	b //= number
	if not a & a - 1 and (not b & b - 1):
		number = int(log2(a * b))
		ans = number // 3 + number % 3 // 2 + number % 3 % 2
	else:
		ans = -1
	print(ans)


def comp(a, b):
	ca = 0
	while a % 2 == 0:
		a = a // 2
		ca += 1
	cb = 0
	while b % 2 == 0:
		b = b // 2
		cb += 1
	if a == b:
		if cb >= ca:
			m = (cb - ca) // 3
			n = (cb - ca - m * 3) // 2
			k = cb - ca - m * 3 - n * 2
			ans = m + n + k
		else:
			m = (ca - cb) // 3
			n = (ca - cb - m * 3) // 2
			k = ca - cb - m * 3 - n * 2
			ans = m + n + k
	else:
		ans = -1
	return ans
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	print(comp(a, b))


def solve(a, b):
	for i in range(len(b)):
		if a[i] != b[i]:
			return -1
	for i in range(len(b), len(a)):
		if a[i] != '0':
			return -1
	res = len(a) - len(b)
	t = 0
	f = res // 3
	t += f
	res -= f * 3
	f = res // 2
	t += f
	res -= f * 2
	f = res // 1
	t += f
	res -= f
	return t
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	a = bin(a)
	b = bin(b)
	if len(a) > len(b):
		print(solve(a, b))
	else:
		print(solve(b, a))


from math import log
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	op = 0
	if b >= a:
		while a < b:
			op += 1
			a = a << 1
	else:
		while a > b:
			if not a & 1:
				op += 1
				a = a >> 1
			else:
				break
	if a == b:
		print(op // 3 + (0 if op % 3 == 0 else 1))
	else:
		print('-1')


import sys
input = sys.stdin.readline
from math import log

def solve(a, b):
	if a == b:
		return 0
	elif b < a:
		(b, a) = (a, b)
		return solve(a, b)
	count = 0
	while a < b:
		count += 1
		(a1, a2, a3) = (a * 2, a * 4, a * 8)
		if a1 == b or a2 == b or a3 == b:
			return count
		elif a3 < b:
			a = a3
		elif a2 < b:
			a = a2
		else:
			a = a1
	return -1
	k = log(b / a, 2)
	if k % 1 == 0:
		count = 0
		while k >= 3:
			count += 1
			k -= 3
		while k >= 2:
			count += 1
			k -= 2
		while k >= 1:
			count += 1
			k -= 1
		return count
	else:
		return -1
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	print(solve(a, b))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if b == a:
		print(0)
		continue
	if b > a:
		cnt = 0
		while a < b:
			a = a * 2
			cnt = cnt + 1
		if a != b:
			print(-1)
		else:
			s = 0
			while cnt > 0:
				if cnt >= 3:
					s = s + 1
					cnt = cnt - 3
				elif cnt == 2:
					s = s + 1
					cnt = cnt - 2
				elif cnt == 1:
					s = s + 1
					cnt = cnt - 1
			print(s)
	else:
		cnt = 0
		f = 0
		while a > b and f == 0:
			if a % 2 != 0:
				f = 1
				break
			a = a // 2
			cnt = cnt + 1
		if a != b:
			print(-1)
		else:
			s = 0
			while cnt > 0:
				if cnt >= 3:
					s = s + 1
					cnt = cnt - 3
				elif cnt == 2:
					s = s + 1
					cnt = cnt - 2
				elif cnt == 1:
					s = s + 1
					cnt = cnt - 1
			print(s)


t = int(input())
for _ in range(t):
	(p, q) = list(map(int, input().split()))
	if p == q:
		print(0)
		continue
	if p > q:
		b = []
		while p > q:
			if p % 2 == 0:
				p = p // 2
				b.append(2)
			else:
				break
		if p == q:
			l = len(b)
			x = l // 3
			y = l % 3
			if y == 2:
				y = 1
			print(x + y)
		else:
			print(-1)
			continue
	if p < q:
		b = []
		while p < q:
			p = p * 2
			b.append(2)
		if p == q:
			l = len(b)
			x = l // 3
			y = l % 3
			if y == 2:
				y = 1
			print(x + y)
		else:
			print(-1)


import sys
from math import ceil
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
for _ in range(int(ri())):
	(a, b) = Ri()
	cnt = 0
	if a < b:
		flag = True
		while a != b:
			if a > b:
				flag = False
				break
			a = a << 1
			cnt += 1
		if flag:
			print(ceil(cnt / 3))
		else:
			print(-1)
	else:
		flag = True
		while a != b:
			if a % 2 == 1:
				flag = False
				break
			a = a >> 1
			cnt += 1
		if flag:
			print(ceil(cnt / 3))
		else:
			print(-1)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
		continue
	if a > b:
		(a, b) = (b, a)
	if b % a != 0:
		print(-1)
		continue
	c = b // a
	ans = 0
	i = 8
	f = 1
	while c != 1:
		if c % i == 0:
			c = c // i
			ans += 1
		else:
			i = i // 2
			if i == 1:
				print(-1)
				f = 2
				break
	if f == 1:
		print(ans)


import queue
import math
t = int(input())

def gcd(a, b):
	if a < b:
		(a, b) = (b, a)
	while a % b:
		r = a % b
		a = b
		b = r
	return b
while t:
	line = input().split()
	(a, b) = (int(line[0]), int(line[1]))
	g = gcd(a, b)
	x = a // g * b // g
	if x & x - 1:
		print(-1)
	else:
		cnt = 0
		flag = True
		while x > 1:
			cnt += 1
			if x % 8 == 0:
				x /= 8
			elif x % 4 == 0:
				x /= 4
			elif x % 2 == 0:
				x /= 2
			else:
				flag = False
				break
		if flag:
			print(cnt)
		else:
			print(-1)
	t -= 1


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	x = min(a, b)
	y = max(a, b)
	ans = -1
	count = 0
	if y % x == 0:
		quo = y // x
		if quo and (not quo & quo - 1):
			quo = len(bin(quo)[2:]) - 1
			count += quo // 3
			quo = quo % 3
			count += quo // 2
			quo = quo % 2
			count += quo // 1
			ans = count
		else:
			ans = -1
	print(ans)


t = int(input())
for i in range(t):
	b = list(map(int, input().split()))
	(a, c) = (b[0], b[1])
	if c == a:
		print(0)
	elif c > a:
		if c % a == 0:
			k = c // a
			p = 2
			i = 1
			while p <= k:
				p = 2 ** i
				if p == k:
					break
				i += 1
			if p == k:
				if i % 3 == 0:
					print(i // 3)
				else:
					print(i // 3 + 1)
			else:
				print(-1)
		else:
			print(-1)
	elif a % c == 0:
		k = a // c
		p = 2
		i = 1
		while p <= k:
			p = 2 ** i
			if p == k:
				break
			i += 1
		if p == k:
			if i % 3 == 0:
				print(i // 3)
			else:
				print(i // 3 + 1)
		else:
			print(-1)
	else:
		print(-1)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	else:
		(maxx, minn) = (max(a, b), min(a, b))
		(d, ans) = (maxx // minn, 0)
		while d != 1:
			if d % 8 == 0:
				d = d // 8
			elif d % 4 == 0:
				d = d // 4
			elif d % 2 == 0:
				d = d // 2
			else:
				break
			ans += 1
		if ans == 0 or d > 1 or maxx % minn != 0:
			print(-1)
		else:
			print(ans)


for _ in range(int(input())):
	l = [8, 4, 2]
	total = 0
	bool = False
	(a, b) = map(int, input().split())
	x = max(a, b)
	y = min(a, b)
	if x % y != 0:
		print(-1)
	else:
		x = x // y
		while x != 1:
			for num in l:
				if x % num == 0:
					x = x // num
					total += 1
					break
			else:
				bool = True
				break
		if bool:
			print(-1)
		else:
			print(total)


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	(a, b) = value()
	flag = True
	if a == b:
		print(0)
		continue
	if a < b:
		step = 0
		while a < b:
			a = a << 1
			step += 1
		if a == b:
			ans = step // 3
			step %= 3
			ans += step // 2 + step % 2
			print(ans)
		else:
			print(-1)
	else:
		step = 0
		while a > b:
			if a % 2:
				flag = False
				break
			a = a >> 1
			step += 1
		if a == b and flag:
			ans = step // 3
			step = step % 3
			ans += step // 2 + step % 2
			print(ans)
		else:
			print(-1)


import sys, math, os
from io import BytesIO, IOBase
from collections import defaultdict as dd, deque, Counter

def data():
	return sys.stdin.readline().strip()

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
sys.setrecursionlimit(100000)
INF = float('inf')
mod = int(1000000000.0) + 7
from decimal import Decimal

def main():
	for i in range(int(data())):
		(a, b) = mdata()
		if a >= b:
			k1 = bin(a)[2:]
			k2 = bin(b)[2:]
			k = len(k1) - len(k2)
			if k1[:len(k2)] == k2 and k1[len(k2):] == '0' * (len(k1) - len(k2)):
				out(k // 3 + k % 3 // 2 + k % 3 % 2 // 1)
			else:
				out(-1)
		else:
			k1 = bin(b)[2:]
			k2 = bin(a)[2:]
			k = len(k1) - len(k2)
			if k1[:len(k2)] == k2 and k1[len(k2):] == '0' * (len(k1) - len(k2)):
				out(k // 3 + k % 3 // 2 + k % 3 % 2 // 1)
			else:
				out(-1)
main()


t = int(input())
for i in range(t):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	test_a = a
	test_b = b
	if a > b:
		operation = 0
		while test_a > test_b:
			test_b = test_b * 2
			operation += 1
			if test_a == test_b:
				if operation % 3 != 0:
					print(operation // 3 + 1)
				else:
					print(operation // 3)
			elif test_b > test_a:
				print(-1)
	elif b > a:
		operation = 0
		while test_b > test_a:
			test_a = test_a * 2
			operation += 1
			if test_a == test_b:
				if operation % 3 != 0:
					print(operation // 3 + 1)
				else:
					print(operation // 3)
			elif test_a > test_b:
				print(-1)
	else:
		print(0)


import math
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	res = 0
	while a < b:
		a *= 2
		res += 1
	if a == b:
		print(math.ceil(res / 3))
	else:
		print(-1)


from math import log2, ceil
rw = int(input())
for ewqr in range(rw):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
		continue
	ab = bin(a)
	bb = bin(b)
	ab = ab[2:]
	bb = bb[2:]
	if len(ab) > len(bb):
		t = True
		for i in range(len(ab)):
			if i < len(bb):
				if ab[i] != bb[i]:
					t = False
					break
			elif ab[i] != '0':
				t = False
				break
		if t:
			f = len(ab) - len(bb)
			print((f + 2) // 3)
		else:
			print(-1)
	else:
		t = True
		for i in range(len(bb)):
			if i < len(ab):
				if ab[i] != bb[i]:
					t = False
					break
			elif bb[i] != '0':
				t = False
				break
		if t:
			f = len(bb) - len(ab)
			print((f + 2) // 3)
		else:
			print(-1)


t = int(input())
from math import log
for i in range(t):
	(a, b) = map(int, input().split())
	if a % b == 0:
		x = a // b
		z = True
		x1 = x
		if x1 % 2 == 0 or x1 == 1:
			while x1 > 1:
				x1 //= 2
				if x1 % 2 != 0 and x1 > 1:
					z = False
					break
		else:
			z = False
		if z == True:
			ans = 0
			while x >= 8:
				x //= 8
				ans += 1
			while x >= 4:
				x //= 4
				ans += 1
			while x >= 2:
				x //= 2
				ans += 1
			print(ans)
		else:
			print(-1)
	elif b % a == 0:
		x = b // a
		z = True
		x1 = x
		if x1 % 2 == 0 or x1 == 1:
			while x1 > 1:
				x1 //= 2
				if x1 % 2 != 0 and x1 > 1:
					z = False
					break
		else:
			z = False
		if z == True:
			ans = 0
			while x >= 8:
				x //= 8
				ans += 1
			while x >= 4:
				x //= 4
				ans += 1
			while x >= 2:
				x //= 2
				ans += 1
			print(ans)
		else:
			print(-1)
	else:
		print(-1)


import sys

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')

def solve(a, b):
	if a == b:
		return 0
	if b > a:
		if b % a > 0:
			return -1
		k = b // a
	else:
		if a % b > 0:
			return -1
		k = a // b
	cnt = 0
	while k >= 8 and k % 8 == 0:
		k //= 8
		cnt += 1
	while k >= 4 and k % 4 == 0:
		k //= 4
		cnt += 1
	while k >= 2 and k % 2 == 0:
		k //= 2
		cnt += 1
	return cnt if k <= 1 else -1

def main():
	for _ in range(ri()):
		(a, b) = ria()
		print(solve(a, b))
main()


import math

def ispower(m, n):
	if m == n:
		return True
	elif n % m != 0:
		return False
	else:
		return ispower(m, n // m)

def compu(a, b):
	if a == b:
		return 0
	else:
		x = max(a, b)
		y = min(a, b)
		if x % y != 0:
			return -1
		elif ispower(2, x // y):
			z = math.log(x // y, 2)
			return int(z) // 3 + min(1, int(z) % 3)
		else:
			return -1
t = int(input())
for i in range(0, t):
	ab = input().split()
	a = int(ab[0])
	b = int(ab[1])
	print(compu(a, b))


n = int(input())
for i in range(n):
	s = input().split()
	a = int(s[0])
	b = int(s[1])
	k = 0
	if a > b:
		while a != b and (not a & 1):
			a = a >> 1
			k += 1
	elif a < b:
		while a != b and (not b & 1):
			b = b >> 1
			k += 1
	if a == b:
		print(int(k / 3) + int(k % 3 != 0))
	else:
		print(-1)


from collections import Counter, defaultdict, deque
from math import *
import sys
input = sys.stdin.readline

def solve():
	(a, b) = sorted((int(x) for x in input().split()))
	a = bin(a)[2:]
	b = bin(b)[2:]
	l = len(a)
	if b[:l] != a or '1' in b[l:]:
		print(-1)
	else:
		res = len(b) - len(a)
		print(ceil(res / 3))
tt = int(input())
for test in range(tt):
	solve()


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	(x, y) = (min(a, b), max(a, b))
	count = 0
	while x < y:
		x = x * 8
		count = count + 1
	if x == y:
		print(count)
	elif x // 4 == y or x // 2 == y:
		print(count)
	else:
		print(-1)


for test in range(int(input())):
	(a, b) = map(int, input().split())
	if a < b:
		(a, b) = (b, a)
	cont = 0
	ok = True
	while a != b and ok:
		if a // 8 >= b and a % 8 == 0:
			a = a // 8
			cont += 1
		elif a // 4 >= b and a % 4 == 0:
			a = a // 4
			cont += 1
		elif a // 2 >= b and a % 2 == 0:
			a = a // 2
			cont += 1
		else:
			ok = False
	if ok:
		print(cont)
	else:
		print(-1)


t = int(input())
for j in range(t):
	(a, b) = map(int, input().split())
	(a, b) = (max(a, b), min(a, b))
	c = 0
	while a > b:
		b = b * 8
		c = c + 1
	if a == b // 2 or a == b // 4 or a == b:
		print(c)
	else:
		print(-1)


t = int(input())
while t > 0:
	(A, B) = map(int, input().split())
	count = 0
	(A, B) = (max(A, B), min(A, B))
	if A > B and A % B == 0:
		while not A == B:
			if A / 8 % B == 0:
				A = A // 8
				count += 1
			elif A / 4 % B == 0:
				A = A // 4
				count += 1
			elif A / 2 % B == 0:
				A = A // 2
				count += 1
			else:
				count = -1
				break
	elif A == B:
		count = 0
	else:
		count = -1
	print(count)
	t -= 1


t = int(input())
for _ in range(t):
	(a, b) = list(map(int, input().split()))
	com = 0
	fim = 0
	cont = 0
	flag = True
	if b == a:
		print('0')
		continue
	if a < b:
		com = a
		fim = b
	else:
		com = b
		fim = a
	while com <= fim:
		if com * 8 <= fim:
			com *= 8
			cont += 1
			continue
		elif com * 4 <= fim:
			com *= 4
			cont += 1
			continue
		elif com * 2 <= fim:
			com *= 2
			cont += 1
			continue
		else:
			break
	if com == fim:
		print(cont)
	else:
		print('-1')


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')
from math import factorial
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

def main():
	for _ in range(N()):
		(a, b) = RL()
		ra = rb = 0
		while a & 1 == 0:
			a >>= 1
			ra += 1
		while b & 1 == 0:
			b >>= 1
			rb += 1
		if a != b:
			print(-1)
		else:
			zero = abs(ra - rb)
			res = 0
			res += zero // 3
			zero = zero % 3
			res += zero // 2
			zero = zero % 2
			res += zero
			print(res)
main()


I = input
for _ in range(int(I())):
	(a1, b1) = map(int, I().split())
	a = a1 if a1 > b1 else b1
	b = b1 if b1 < a1 else a1
	if a % b != 0:
		print('-1')
	else:
		t = a // b
		c = 0
		while t % 8 == 0:
			t //= 8
			c += 1
		while t % 4 == 0:
			t //= 4
			c += 1
		while t % 2 == 0:
			t //= 2
			c += 1
		if t != 1:
			print('-1')
		else:
			print(c)


import math
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	(a, b) = (max(a, b), min(a, b))
	if a % b == 0:
		ans = 0
		t = bin(a // b)[2:]
		if t.count('1') == 1:
			t = len(t) - 1
			ans += t // 3
			t = t % 3
			ans += t // 2
			t = t % 2
			ans += t
			print(int(ans))
		else:
			print(-1)
	else:
		print(-1)


from sys import stdin
input = stdin.buffer.readline
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	res = 0
	if a == b:
		print(0)
	else:
		if a < b:
			(a, b) = (b, a)
		if a % b == 0:
			a //= b
			if bin(a).count('1') == 1:
				while a >= 8:
					a //= 8
					res += 1
				while a >= 4:
					a //= 4
					res += 1
				while a >= 2:
					a //= 2
					res += 1
				print(res)
			else:
				print(-1)
		else:
			print(-1)


import sys
from math import log2, floor
TEST = 0
if TEST == 1:
	input_file = open('inputA.txt', 'r')
	input_from_file = input_file.readlines()

def read_int():
	if TEST:
		return int(input_from_file.pop(0))
	else:
		return int(sys.stdin.readline())

def read_ints():
	if TEST:
		return list(map(int, input_from_file.pop(0).rstrip().split()))
	else:
		return list(map(int, sys.stdin.readline().split()))
t = read_int()

def howmanysteps(a, b):
	bm = max(a, b)
	am = min(a, b)
	num = 0
	while am < bm:
		num += 1
		am *= 2
	num = int((num + 2) / 3)
	if am != bm:
		return -1
	else:
		return num
for test in range(t):
	(a, b) = read_ints()
	ans = howmanysteps(a, b)
	print(ans)


from math import *
from atexit import register
from io import StringIO
import sys
_IB = sys.stdin.read().splitlines()
input = iter(_IB).__next__
_OB = StringIO()
sys.stdout = _OB

@register
def write():
	sys.__stdout__.write(_OB.getvalue())

def Iint():
	return int(input())

def Ilist():
	return list(map(int, input().split()))

def Imap():
	return map(int, input().split())

def Plist(li, s=' '):
	print(s.join(map(str, li)))

def main():
	pow2 = dict()
	for i in range(61):
		pow2[1 << i] = i
	t = Iint()
	for _ in range(t):
		(a, b) = Imap()
		if a == b:
			print(0)
		elif a < b:
			if b % a == 0 and b // a in pow2:
				x = pow2[b // a]
				if x % 3 == 0:
					x = x // 3
				else:
					x = ceil(x / 3)
				print(x)
			else:
				print(-1)
		elif a > b:
			if a % b == 0 and a // b in pow2:
				x = pow2[a // b]
				if x % 3 == 0:
					x = x // 3
				else:
					x = ceil(x / 3)
				print(x)
			else:
				print(-1)
main()


import math
for _ in range(int(input())):
	count = 0
	(n, m) = map(int, input().split())
	larger = max(n, m)
	smaller = min(n, m)
	while larger > smaller:
		smaller *= 2
		count += 1
	if larger == smaller:
		print(math.ceil(count / 3))
	else:
		print('-1')


import math
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	elif a < b:
		p = int(math.log2(b / a))
		if a * 2 ** p == b:
			print(p // 3 + p % 3 // 2 + p % 3 % 2)
		else:
			print(-1)
	else:
		p = int(math.log2(a / b))
		if b * 2 ** p == a:
			print(p // 3 + p % 3 // 2 + p % 3 % 2)
		else:
			print(-1)


def find(a, b):
	if a == b:
		return 0
	x = max(a, b)
	y = min(a, b)
	A = [2, 4, 8]
	if x % y == 0:
		c = 1
		z = x // y
		while True:
			if z in A:
				return c
			if z % 8 == 0:
				z = z // 8
				c += 1
			elif z % 4 == 0:
				z = z // 4
				c += 1
			elif z % 2 == 0:
				z = z // 2
				c += 1
			else:
				return -1
	else:
		return -1
T = int(input())
for _ in range(T):
	(a, b) = list(map(int, input().split()))
	print(find(a, b))


def yesh(a1, b1, k):
	if b1 >= a1:
		if b1 == a1:
			print(k)
			return
		else:
			print(-1)
			return
	elif b1 * 8 <= a1:
		b1 = b1 * 8
		k += 1
		yesh(a1, b1, k)
	elif b1 * 4 <= a1:
		k += 1
		b1 = b1 * 4
		yesh(a1, b1, k)
	else:
		b1 = b1 * 2
		k += 1
		yesh(a1, b1, k)
t = int(input())
while t > 0:
	(a, b) = map(int, input().split())
	a1 = max(a, b)
	b1 = min(a, b)
	k = 0
	yesh(a1, b1, k)
	t -= 1


def two_power(a, b):
	count = 0
	while b > a:
		a = 2 * a
		count += 1
	if b == a:
		return count
	return -1
for t in range(int(input())):
	(a, b) = list(map(int, input().split()))
	if b > a:
		count = two_power(a, b)
	else:
		count = two_power(b, a)
	if count == -1:
		print(-1)
	else:
		operations = 0
		operations += count // 3
		count = count % 3
		operations += count // 2
		count = count % 2
		operations += count
		print(operations)


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	k = b // a
	d = 1
	c = 0
	while d < k:
		d *= 2
		c += 1
	if a * 2 ** c == b:
		v = c - 3 * (c // 3)
		g = v - 2 * (v // 2)
		print(c // 3 + v // 2 + g % 2)
	else:
		print(-1)


t = int(input())
oper = [2, 4, 8]
for i in range(t):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
		continue
	if a > b:
		(a, b) = (b, a)
	count = 0
	newa = a
	flag = 0
	while 1:
		newa *= 8
		if newa == b:
			count += 1
			flag = 1
			break
		if newa < b:
			a = newa
			count += 1
		else:
			break
	if flag == 1:
		print(count)
		continue
	newa = a
	while 1:
		newa *= 4
		if newa == b:
			count += 1
			flag = 1
			break
		if newa < b:
			a = newa
			count += 1
		else:
			break
	if flag == 1:
		print(count)
		continue
	newa = a
	while 1:
		newa *= 2
		if newa == b:
			count += 1
			flag = 1
			break
		if newa < b:
			a = newa
			count += 1
		else:
			break
	if flag == 1:
		print(count)
	else:
		print(-1)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	count = 0
	if b > a:
		while b > a:
			if b >= 2 * a:
				a *= 2
				count += 1
			else:
				break
	if b < a:
		while b < a:
			if b <= a // 2 and a % 2 == 0:
				a //= 2
				count += 1
			else:
				break
	if a == b:
		print(count // 3 + count % 3 // 2 + count % 3 % 2)
	else:
		print(-1)


import math
t = int(input())
for _ in range(t):
	(a, b) = [int(x) for x in input().split()]
	gc = math.gcd(a, b)
	a = a // gc
	b = b // gc
	if a == 1:
		msb = math.frexp(b)[1] - 1
		if b != 1 << msb:
			print(-1)
		elif msb % 3 == 0:
			print(msb // 3)
		else:
			print(msb // 3 + 1)
	elif b == 1:
		msb = math.frexp(a)[1] - 1
		if a != 1 << msb:
			print(-1)
		elif msb % 3 == 0:
			print(msb // 3)
		else:
			print(msb // 3 + 1)
	else:
		print(-1)


def xyz(x, y):
	num = 0
	while x > y:
		if y * 8 <= x:
			y = y * 8
			num += 1
		elif y * 4 <= x:
			num += 1
			y = y * 4
		else:
			num += 1
			y = y * 2
	if x != y:
		return -1
	else:
		return num
for num in range(int(input())):
	(x, y) = map(int, input().split())
	print(xyz(max(x, y), min(x, y)))


import sys

def I():
	return sys.stdin.readline().rstrip()
for tc in range(1, 1 + int(I())):
	(a, b) = list(map(int, I().split()))
	(al, bl) = (0, 0)
	while a > 0 and a % 2 == 0:
		al += 1
		a //= 2
	while b > 0 and b % 2 == 0:
		bl += 1
		b //= 2
	if a == b:
		d = abs(al - bl)
		print((d + 2) // 3)
	else:
		print(-1)


tc = int(input())
for _ in range(tc):
	(x, y) = [int(i) for i in input().split(' ')]
	xc = 0
	yc = 0
	if x > 0:
		while x & 1 == 0:
			x = x >> 1
			xc += 1
	if y > 0:
		while y & 1 == 0:
			y = y >> 1
			yc += 1
	if x != y:
		print(-1)
		continue
	else:
		count = 0
		v = abs(xc - yc)
		count += v // 3
		v = v % 3
		count += v // 2
		v = v % 2
		count += v
		print(count)


from sys import stdin, stdout
from collections import deque
R = lambda : stdin.readline().strip()
RL = lambda : list(map(int, R().split(' ')))
T = int(R())
for _ in range(T):
	flag = 1
	(a, b) = RL()
	if b > a:
		if b % a != 0:
			flag = 0
		else:
			dif = b // a
	elif a % b != 0:
		flag = 0
	else:
		dif = a // b
	if flag == 0:
		print(-1)
		continue
	cnt1 = bin(dif).count('1')
	cnt0 = bin(dif).count('0') - 1
	if cnt1 != 1:
		print(-1)
	else:
		ans = cnt0 // 3
		if cnt0 % 3 != 0:
			ans += 1
		print(ans)


kl = int(input())
for l in range(kl):
	(a, b) = map(int, input().split())
	pr = 1
	if a % b == 0 or b % a == 0:
		if a >= b:
			k = a // b
		else:
			k = b // a
		(ans, m) = (0, 0)
		while k > 2 ** m:
			m += 1
		if 2 ** m != k:
			pr = 0
		else:
			ans = m // 3 + m % 3 // 2 + m % 3 % 2
	else:
		pr = 0
	if pr:
		print(ans)
	else:
		print(-1)


t = int(input())
while t:
	t -= 1
	(a, b) = map(int, input().split())
	step = 0
	flag = True if a <= b else False
	err = 0
	while a != b:
		if flag:
			if a * 8 <= b:
				a = a * 8
			elif a * 4 <= b:
				a = a * 4
			elif a * 2 <= b:
				a = a * 2
			else:
				err = 1
				break
			step += 1
		else:
			if a % 8 == 0 and a // 8 >= b:
				a = a // 8
			elif a % 4 == 0 and a // 4 >= b:
				a = a // 4
			elif a % 2 == 0 and a // 2 >= b:
				a = a // 2
			else:
				err = 1
				break
			step += 1
	if err:
		print(-1)
		continue
	print(step)


t = int(input())
import math
for _ in range(t):
	(a, b) = map(int, input().split())
	if a < b:
		if b % a != 0:
			print(-1)
			continue
		if b // a % 2 != 0:
			print(-1)
			continue
		z = int(math.log2(b // a))
		if b // a != 2 ** z:
			print(-1)
			continue
		count = z // 3
		z = z % 3
		count += z // 2
		z = z % 2
		count += z
		print(count)
	elif a > b:
		if a % b != 0:
			print(-1)
			continue
		if a // b % 2 != 0:
			print(-1)
			continue
		z = int(math.log2(a // b))
		if a // b != 2 ** z:
			print(-1)
			continue
		count = z // 3
		z = z % 3
		count += z // 2
		z = z % 2
		count += z
		print(count)
	else:
		print(0)


import sys
import math

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	(a, b) = get_ints()
	count = 0
	flag = 0
	if a > b:
		(a, b) = (b, a)
	if a == b:
		print(0)
	else:
		d = a
		while 1:
			d = d * 2
			count = count + 1
			if d == b:
				flag = 1
				break
			if d > b:
				break
		if flag == 1:
			x = count % 3
			y = count // 3
			if x == 0:
				print(y)
			else:
				print(y + 1)
		else:
			print(-1)


n = int(input())

def solve(a, b):
	if a == b:
		return 0
	ops = 0
	if a > b:
		while a > b and a & 1 == 0:
			c = False
			for i in [8, 4, 2]:
				if a % i == 0 and a // i >= b:
					c = True
					a //= i
					ops += 1
					break
			if a == b:
				return ops
			if c == False:
				break
	elif a < b:
		while a < b:
			c = False
			for i in [8, 4, 2]:
				if a * i <= b:
					c = True
					a *= i
					ops += 1
					break
			if a == b:
				return ops
			if not c:
				break
	return -1
for _ in range(n):
	(a, b) = list(map(int, input().split()))
	print(solve(a, b))


from sys import stdin
input = stdin.readline

def lg(k):
	res = 0
	while k % 2 == 0:
		k //= 2
		res += 1
	if k == 1:
		return res
	else:
		return -5
for _ in range(int(input())):
	(a, b) = sorted(map(int, input().split()))
	print(-1 if b % a else (lg(b // a) + 2) // 3)


dp = [0] * 10 ** 5
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	x = a
	while x % 2 == 0:
		x //= 2
	if b % x != 0 or bin(b // x).count('1') != 1:
		print(-1)
		continue
	c = 0
	x = a
	while x % 2 == 0 and (b % x != 0 or bin(b // x).count('1') != 1):
		x //= 2
		c += 1
	t1 = c // 3 + int(c % 3 != 0)
	c = bin(b // x)[::-1].index('1')
	t2 = c // 3 + int(c % 3 != 0)
	print(t1 + t2)


from math import ceil as c

def h2(n1, n2, k1, k2):
	while n1 % 2 == 0:
		n1 //= 2
		k1 += 1
	while n2 % 2 == 0:
		n2 //= 2
		k2 += 1
	print(c(abs(k1 - k2) / 3)) if n1 == n2 else print(-1)
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	h2(a, b, 0, 0)


import io, sys, atexit, os
import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations
from itertools import combinations

def li():
	return list(map(int, sys.stdin.readline().split()))

def num():
	return map(int, sys.stdin.readline().split())

def nu():
	return int(input())

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def lcm(x, y):
	gg = find_gcd(x, y)
	return x * y // gg
mm = 1000000007

def solve():
	t = nu()
	for tt in range(t):
		(a, b) = num()
		if a > b:
			(a, b) = (b, a)
		cc = 0
		while a < b:
			if a * 8 <= b:
				a *= 8
			elif a * 4 <= b:
				a *= 4
			else:
				a *= 2
			cc += 1
		if a != b:
			print(-1)
		else:
			print(cc)
solve()


for i in range(int(input())):
	(a, b) = map(int, input().split())
	ans = 0
	if a > b:
		(a, b) = (b, a)
	while a * 8 <= b:
		a = a * 8
		ans += 1
	while a * 4 <= b:
		a = a * 4
		ans += 1
	while a * 2 <= b:
		a = a * 2
		ans += 1
	if a == b:
		print(ans)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	(a, b) = list(map(int, input().split()))
	if a < b:
		(a, b) = (b, a)
	ans = -1
	for i in range(60):
		if b * 2 ** i == a:
			ans = i // 3 + (i % 3 != 0)
			break
	print(ans)


import math
for w in range(int(input())):
	n = list(map(int, input().split()))
	n.sort()
	if n[0] == n[1]:
		print(0)
	elif n[0] * 2 == n[1]:
		print(1)
	elif n[0] * 4 == n[1]:
		print(1)
	elif n[0] * 8 == n[1]:
		print(1)
	else:
		cont = 2
		flag = 0
		rep = 16
		while True:
			if n[0] * rep >= n[1]:
				break
			rep *= 2
			flag += 1
			if flag == 3:
				cont += 1
				flag = 0
		if n[0] * rep == n[1]:
			print(cont)
		else:
			print(-1)


from sys import stdin
import math

def iinput():
	return int(stdin.readline())

def sinput():
	return input()

def minput():
	return map(int, stdin.readline().split())

def linput():
	return list(map(int, stdin.readline().split()))

def f(n):
	while n % 2 == 0:
		n //= 2
	return n
t = iinput()
while t:
	t -= 1
	(a, b) = minput()
	if a > b:
		(a, b) = (b, a)
	if a == b:
		print(0)
	elif f(a) != f(b):
		print(-1)
	else:
		x = b / a
		ans = 0
		d = int(math.log(x, 8))
		x = x / 8 ** d
		ans += d
		d = int(math.log(x, 4))
		x = x / 4 ** d
		ans += d
		d = int(math.log(x, 2))
		x = x / 2 ** d
		ans += d
		if ans == 0:
			ans = -1
		print(ans if x == 1 else -1)


def process(now):
	count = 0
	if now == 1:
		return 0
	if now % 2 != 0:
		return -1
	while now >= 1:
		if now == 1:
			return count
		if now % 8 == 0:
			count += 1
			now //= 8
		elif now % 4 == 0:
			count += 1
			now //= 4
		elif now % 2 == 0:
			count += 1
			now //= 2
		else:
			return -1
	return -1
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a >= b:
		if a % b != 0:
			print(-1)
		else:
			print(process(a // b))
	elif b % a != 0:
		print(-1)
	else:
		print(process(b // a))


for i in range(int(input())):
	(a, b) = map(int, input().split())
	c = a
	if a < b:
		a = b
		b = c
	c = a
	flag = 0
	count = 0
	while c != b:
		if c % 2 != 0:
			flag = 1
			break
		c //= 2
		count += 1
	if flag == 1:
		print(-1)
	else:
		print(count // 3 + (count - count // 3 * 3) // 2 + (count - count // 3 * 3 - (count - count // 3 * 3) // 2 * 2))


import os
import sys
from io import BytesIO, IOBase
import math
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a < b:
		(a, b) = (b, a)
	if a == b:
		print('0')
	else:
		d = a // b
		if d * b != a:
			print('-1')
			continue
		else:
			ans = 0
			f = True
			while d > 1:
				if d % 8 == 0:
					d //= 8
					ans += 1
				elif d % 4 == 0:
					d //= 4
					ans += 1
				elif d % 2 == 0:
					d //= 2
					ans += 1
				else:
					f = False
					break
			if f:
				print(ans)
			else:
				print('-1')


import math
t = int(input())
while t != 0:
	(a, b) = map(int, input().split())
	less = 0
	great = 0
	if a < b:
		less = a
		great = b
	else:
		less = b
		great = a
	step = 0
	while less < great:
		less = less << 1
		step += 1
	result = -1
	if less > great:
		result = -1
	elif step % 3 == 0:
		result = int(step / 3)
	else:
		result = math.floor(step / 3) + 1
	print(result)
	t -= 1


t = int(input())
for i in range(t):
	(a, b) = input().split()
	(a, b) = (int(a), int(b))
	if a > b:
		if a % b == 0 and a % 2 == 0:
			counter = 0
			while b < a:
				b *= 2
				counter += 1
			if b == a:
				if counter > 3:
					d = counter // 3
					if counter % 3 is not 0:
						d += 1
				else:
					d = 1
				print(d)
			else:
				print(-1)
		else:
			print(-1)
	elif a < b:
		if b % a == 0 and b % 2 == 0:
			counter = 0
			while a < b:
				a *= 2
				counter += 1
			if a == b:
				if counter > 3:
					d = counter // 3
					if counter % 3 is not 0:
						d += 1
				else:
					d = 1
				print(d)
			else:
				print(-1)
		else:
			print(-1)
	else:
		print(0)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	(x, y) = (min(a, b), max(a, b))
	k = 0
	while x < y:
		x *= 2
		k += 1
	if x == y:
		q = k // 3
		r = k % 3 // 2
		s = (k - q * 3 - r * 2) % 2
		print(q + r + s)
	else:
		print(-1)


def solve(b, s):
	for i in range(len(s)):
		if b[i] != s[i]:
			return -1
	cnt = 0
	for i in range(len(s), len(b)):
		if b[i] == '0':
			cnt += 1
		else:
			return -1
	sum1 = 0
	sum1 += cnt // 3
	cnt = cnt % 3
	sum1 += cnt // 2
	cnt = cnt % 2
	sum1 += cnt
	return sum1
t = int(input())
while t:
	t -= 1
	x = [int(i) for i in input().split()]
	b = max(x)
	s = min(x)
	(b, s) = (bin(b)[2:], bin(s)[2:])
	print(solve(b, s))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	elif b > a:
		if b % a != 0:
			print(-1)
		else:
			c = b // a
			(x, y, z) = (0, 0, 0)
			while c % 8 == 0:
				x += 1
				c = c // 8
			while c % 4 == 0:
				y += 1
				c = c // 4
			while c % 2 == 0:
				z += 1
				c = c // 2
			if c == 1:
				print(x + y + z)
			else:
				print(-1)
	elif a % b != 0:
		print(-1)
	else:
		c = a // b
		(x, y, z) = (0, 0, 0)
		while c % 8 == 0:
			x += 1
			c = c // 8
		while c % 4 == 0:
			y += 1
			c = c // 4
		while c % 2 == 0:
			z += 1
			c = c // 2
		if c == 1:
			print(x + y + z)
		else:
			print(-1)


n = int(input())
for elem in range(n):
	s = input().split()
	a = int(s[0])
	b = int(s[1])
	i_a = 0
	while a % 2 == 0:
		a = a // 2
		i_a += 1
	i_b = 0
	while b % 2 == 0:
		b = b // 2
		i_b += 1
	if a == b:
		s = (max(i_a, i_b) - min(i_a, i_b)) // 3
		if (max(i_a, i_b) - min(i_a, i_b)) % 3 != 0:
			s += 1
		print(s)
	else:
		print(-1)


import math
b = int(input())
for k in range(b):
	(a, c) = list(map(int, input().split()))
	if a >= c:
		d = math.log2(a / c)
		d = math.ceil(d)
		c = c * 8 ** (d // 3) * 4 ** (d % 3 // 2) * 2 ** (d % 3 % 2)
	else:
		d = math.log2(c / a)
		d = math.ceil(d)
		a = a * 8 ** (d // 3) * 4 ** (d % 3 // 2) * 2 ** (d % 3 % 2)
	if a == c:
		print(d // 3 + d % 3 // 2 + d % 3 % 2)
	else:
		print(-1)


import math
tests = int(input())
for i in range(tests):
	numbers = input().split(' ')
	a = int(numbers[0])
	b = int(numbers[1])
	if a == b:
		print(0)
	else:
		if a < b:
			temp = a
			a = b
			b = temp
		multi = 8
		step = 0
		while multi > 1:
			if a >= multi * b:
				b = b * multi
				step += 1
			else:
				multi = multi // 2
		if a == b:
			print(step)
		else:
			print(-1)


import math
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	(a, b) = (max(a, b), min(a, b))
	if a == b:
		print(0)
	elif a % b != 0:
		print(-1)
	else:
		x = a // b
		count = 0
		while x % 8 == 0:
			x //= 8
			count += 1
		while x % 4 == 0:
			x //= 4
			count += 1
		while x % 2 == 0:
			x //= 2
			count += 1
		if x == 1:
			print(count)
		else:
			print(-1)


from collections import defaultdict
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k > n:
		(n, k) = (k, n)
	if n == k:
		print(0)
		continue
	count = -1
	if n % k == 0 and n // k % 2 == 0:
		n = n // k
		count = 0
		while n > 0 and n % 8 == 0:
			n = n // 8
			count += 1
		while n > 0 and n % 4 == 0:
			n = n // 4
			count += 1
		while n > 0 and n % 2 == 0:
			n = n // 2
			count += 1
	if n == 1:
		print(count)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	(x, y) = map(int, input().split())
	if y > x:
		(x, y) = (y, x)
	if x == y:
		print(0)
	elif x % y == 0:
		(temp, mid) = (0, y)
		while mid < x:
			mid = mid * 2
			temp += 1
		if mid == x:
			mid = 0
			mid = temp // 3
			if temp % 3 != 0:
				mid += 1
			print(mid)
		else:
			print(-1)
	else:
		print(-1)


def main():
	T = int(input())
	for i in range(T):
		(a, b) = map(int, input().split())
		if a == b:
			print(0)
		else:
			if a < b:
				c = a
				a = b
				b = c
			num = 0
			flag = 0
			c = a // b
			if c * b == a:
				while c > 1:
					if c % 2 == 0:
						c = c // 2
						num += 1
					else:
						flag = 1
						print(-1)
						break
				if flag == 0:
					k1 = num // 3
					num = num - k1 * 3
					k2 = num // 2
					num = num - k2 * 2
					print(k1 + k2 + num)
			else:
				print(-1)
main()


for i in range(int(input())):
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	steps = 0
	while a < b:
		a *= 2
		steps += 1
	if a != b:
		print(-1)
		continue
	else:
		steps = int(steps)
		print(steps // 3 if steps % 3 == 0 else steps // 3 + 1)


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return [int(i) for i in input().split()]

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)
for _ in range(ii()):
	(a, b) = mi()
	(ta, tb) = (0, 0)
	while a % 2 == 0:
		a //= 2
		ta += 1
	while b % 2 == 0:
		b //= 2
		tb += 1
	if a != b:
		print(-1)
	else:
		print(math.ceil(abs(ta - tb) / 3))


import sys
tests = int(sys.stdin.readline().rstrip())
for test in range(tests):
	values = sys.stdin.readline().rstrip().split(' ')
	a = int(values[0])
	b = int(values[1])
	if a == b:
		print(0)
		continue
	if a < b:
		tmp = b
		b = a
		a = tmp
	if a % b == 0:
		ops = 0
		for divisor in [8, 4, 2]:
			while a % divisor == 0 and a // divisor >= b:
				a = a // divisor
				ops += 1
		if a != b:
			ops = -1
		print(ops)
	else:
		print(-1)


for t in range(int(input())):
	(a, b) = map(int, input().split())
	if a < b:
		(a, b) = (b, a)
	b = bin(b)[2:]
	a = bin(a)[2:]
	rem = len(a) - len(b)
	b += ''.join(['0' for i in range(rem)])
	if int(a) ^ int(b) == 0:
		steps = 0
		steps += rem // 3
		rem %= 3
		steps += rem // 2
		rem = rem % 2
		steps += rem
		print(steps)
	else:
		print(-1)


s = []
ans = 1
for i in range(1, 61):
	ans *= 2
	s.append(ans)
for _ in range(int(input())):
	arr = [int(x) for x in input().split()]
	(a, b) = (arr[0], arr[1])
	ans = 0
	if b == a:
		ans = 0
	elif b > a:
		if b & 1 == 1:
			ans = -1
		elif b % a != 0:
			ans = -1
		else:
			c = b // a
			if c not in s:
				ans = -1
			else:
				pow = s.index(c)
				pow += 1
				ans += pow // 3
				pow = pow % 3
				ans += pow // 2
				pow = pow % 2
				ans += pow
	elif a % b != 0:
		ans = -1
	elif a // b & 1 == 1:
		ans = -1
	elif a // b not in s:
		ans = -1
	else:
		c = a // b
		pow = s.index(c)
		pow += 1
		ans += pow // 3
		pow = pow % 3
		ans += pow // 2
		pow = pow % 2
		ans += pow
	print(ans)


t = int(input(''))
for _ in range(t):
	[a, b] = list(map(int, input().split()))
	if a == b:
		print(0)
		continue
	ans = 0
	while a % 2 == 0:
		ans += 1
		a = a // 2
	while b % 2 == 0:
		ans -= 1
		b = b // 2
	if a != b:
		print(-1)
		continue
	if ans < 0:
		ans *= -1
	print((ans + 2) // 3)


from sys import stdin
from math import log

def iinput():
	return int(stdin.readline())

def sinput():
	return input()

def minput():
	return map(int, stdin.readline().split())

def linput():
	return list(map(int, stdin.readline().split()))
t = iinput()
while t:
	t -= 1
	(a, b) = minput()
	if a > b:
		(a, b) = (b, a)
	if a == b:
		print(0)
	elif b % a != 0:
		print(-1)
	else:
		ans = 0
		if b // a % 2 == 0:
			x = b / a
			temp = -1
			d = int(log(x, 2))
			if b == a * (1 << d + 1):
				temp = d + 1
			elif b == a * (1 << d):
				temp = d
			elif b == a * (1 << d - 1):
				temp = d - 1
			ans = 0
			if temp != -1:
				for i in range(3, 0, -1):
					ans += temp // i
					temp = temp % i
			else:
				ans = -1
		else:
			ans = -1
		print(ans)


import math
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	x = a
	y = b
	while True:
		if a % 2 == 0:
			a //= 2
		if b % 2 == 0:
			b //= 2
		elif a % 2 != 0 and b % 2 != 0:
			break
	if a != b:
		print(-1)
	else:
		if x > y:
			(y, x) = (x, y)
		ans = 0
		y //= x
		while y >= 8:
			y //= 8
			ans += 1
		if y > 1:
			ans += 1
		print(ans)


from math import log2
t = int(input())

def power_of_two(n):
	i = 0
	while n != 1 and n % 2 == 0:
		n //= 2
		i += 1
	return (n == 1, i)
for _ in range(t):
	(a, b) = map(int, input().split())
	if b > a:
		(a, b) = (b, a)
	if a % b != 0:
		print(-1)
	else:
		(ok, ans) = power_of_two(a // b)
		if not ok:
			print(-1)
		else:
			ans = int(ans)
			ans3 = ans // 3
			ans -= ans3 * 3
			ans2 = ans // 2
			ans -= ans2 * 2
			print(ans + ans2 + ans3)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	(a, b) = (max(a, b), min(a, b))
	if a % b:
		print(-1)
	else:
		k = a // b
		r = 0
		while k > 1:
			if k & 1:
				print(-1)
				break
			k //= 2
			r += 1
		else:
			print((r - 1) // 3 + 1)


import math
t = int(input())
while t:
	t += -1
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	if b % a:
		print(-1)
	else:
		ttt = b // a
		while ttt % 2 == 0:
			ttt //= 2
		if ttt != 1:
			print(-1)
		else:
			tmp = math.log(b // a, 8)
			print(math.ceil(math.log(b // a, 8) - 1e-08))


import sys
import math
import heapq
import collections

def inputnum():
	return int(input())

def inputnums():
	return map(int, input().split())

def inputlist():
	return list(map(int, input().split()))

def inputstring():
	return [x for x in input()]

def inputmatrix(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d
t = int(input())
for q in range(t):
	(a, b) = inputnums()
	cnt = 0
	if a == b:
		print(0)
		continue
	if a // b >= 2 and a % b == 0:
		while a > b:
			b *= 2
			cnt += 1
		if a == b:
			if cnt % 3 == 0:
				print(cnt // 3)
				continue
			else:
				print(cnt // 3 + 1)
				continue
		else:
			print(-1)
			continue
	if b // a >= 2 and b % a == 0:
		while a < b:
			a *= 2
			cnt += 1
		if a == b:
			if cnt % 3 == 0:
				print(cnt // 3)
				continue
			else:
				print(cnt // 3 + 1)
				continue
		else:
			print(-1)
			continue
	print(-1)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	(a, b) = (max(a, b), min(a, b))
	if a == b:
		print(0)
		continue
	sa = list(bin(a)[2:])
	sb = list(bin(b)[2:])
	cnt = 0
	while sa != sb and len(sa) > 0 and (sa[-1] != '1'):
		sa.pop()
		cnt += 1
	if sa == sb:
		ans = 0
		while cnt >= 3:
			cnt -= 3
			ans += 1
		while cnt >= 2:
			cnt -= 2
			ans += 1
		ans += cnt
		print(ans)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	flag = True
	ans = 0
	if a < b:
		flag = False
		while True:
			if a == b:
				flag = True
				break
			elif a > b:
				break
			else:
				a = a * 2
				ans += 1
		if flag:
			ch = ans // 3
			ans %= 3
			ch += ans // 2
			ans %= 2
			ch += ans
			print(ch)
		else:
			print(-1)
	elif a == b:
		print(0)
	else:
		flag = False
		while True:
			if a == b:
				flag = True
				break
			elif a < b:
				break
			elif a % 2 == 0:
				a = a // 2
				ans += 1
			else:
				break
		if flag:
			ch = ans // 3
			ans %= 3
			ch += ans // 2
			ans %= 2
			ch += ans
			print(ch)
		else:
			print(-1)


for test in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	elif a % 2 != 0 and b % 2 != 0:
		print(-1)
	elif a % b != 0 and b % a != 0:
		print(-1)
	else:
		if a > b:
			x = a // b
		else:
			x = b // a
		count = 0
		while x != 1:
			flag = 0
			if x % 8 == 0:
				count += 1
				x //= 8
				flag = 1
			elif x % 4 == 0:
				count += 1
				x //= 4
				flag = 1
			elif x % 2 == 0:
				x //= 2
				count += 1
				flag = 1
			if flag == 0:
				break
		if flag == 1:
			print(count)
		else:
			print(-1)


import math
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	elif a > b:
		if a % b == 0:
			c = a // b
			v = 1
			d = 0
			for j in range(1, 61):
				v *= 2
				if c == v:
					if j % 3 == 0:
						b = 0
					else:
						b = 1
					print(b + j // 3)
					d = 1
					break
				elif c < v:
					break
			if d == 0:
				print(-1)
		else:
			print(-1)
	elif b % a == 0:
		c = b // a
		v = 1
		d = 0
		for j in range(1, 61):
			v *= 2
			if c == v:
				if j % 3 == 0:
					b = 0
				else:
					b = 1
				print(b + j // 3)
				d = 1
				break
			elif c < v:
				break
		if d == 0:
			print(-1)
	else:
		print(-1)


for _ in range(int(input())):
	(m, n) = map(int, input().split())
	l = [2 ** i for i in range(64)]
	if m == n:
		print(0)
	else:
		if n > m:
			(m, n) = (n, m)
		if m % n == 0:
			if m // n in l:
				ind = l.index(m // n)
				if ind % 3 == 0:
					print(ind // 3)
				else:
					print(ind // 3 + 1)
			else:
				print(-1)
		else:
			print(-1)


def Johnny_and_Ancient_Computer(a, b):
	cnt = 0
	(b, a) = (max(a, b), min(a, b))
	if a == b:
		return 0
	else:
		while a < b:
			if a * 8 <= b:
				a *= 8
				cnt += 1
			elif a * 4 <= b:
				a *= 4
				cnt += 1
			elif a * 2 <= b:
				a *= 2
				cnt += 1
			else:
				return -1
		return cnt
t = input()
for i in range(int(t)):
	(a, b) = map(int, input().split())
	print(Johnny_and_Ancient_Computer(a, b))


def f(n):
	if n == 0:
		return False
	while n != 1:
		if n % 2 != 0:
			return False
		n = n // 2
	return True

def give(n):
	c = 0
	while n != 1:
		if n % 8 == 0:
			c += 1
			n = n // 8
		elif n % 4 == 0:
			c += 1
			n = n // 4
		else:
			c += 1
			n = n // 2
	return c
for _ in range(int(input())):
	(a, b) = [int(x) for x in input().split()]
	c = 0
	if a == b:
		print(c)
	elif a > b:
		if a % b == 0 and f(a // b):
			print(give(a // b))
		else:
			print(-1)
	elif b % a == 0 and f(b // a):
		print(give(b // a))
	else:
		print(-1)


testcases = int(input())
for testcase in range(testcases):
	temparr = input()
	temparr = temparr.split()
	first = int(temparr[0])
	second = int(temparr[1])
	if first == second:
		print(0)
		continue
	if first & 1 and second & 1:
		print(-1)
		continue
	no3 = 0
	no2 = 0
	no1 = 0
	if second > first:
		time = 0
		count = 0
		while second > first:
			if first == second:
				break
			count += 1
			first = first << 1
		if first != second:
			print('-1')
			continue
		no3 = count // 3
		count -= no3 * 3
		no2 = count // 2
		count -= no2 * 2
		no1 = count
		print(no3 + no2 + no1)
	else:
		time = 0
		count = 0
		flag = 0
		while first > second:
			if first == second:
				break
			if first & 1:
				flag = 1
				break
			count += 1
			first = first >> 1
			if first == second:
				break
		if flag == 1:
			print('-1')
			continue
		if first != second:
			print('-1')
			continue
		no3 = count // 3
		count -= no3 * 3
		no2 = count // 2
		count -= no2 * 2
		no1 = count
		print(no3 + no2 + no1)


def find_result(cnt):
	result = 0
	result = result + cnt // 3
	remaining = cnt % 3
	result = result + remaining // 2
	remaining = remaining % 2
	result = result + remaining
	return result
t = int(input())
for each_t in range(t):
	(a, b) = input().split()
	(a, b) = (int(a), int(b))
	result = 0
	if a == b:
		result = 0
	elif a > b:
		cnt = 0
		while a > b:
			if a & 1 == 0:
				a = a >> 1
			else:
				break
			cnt = cnt + 1
		if a == b:
			result = find_result(cnt)
		else:
			result = -1
	else:
		cnt = 0
		while a < b:
			a = a << 1
			cnt = cnt + 1
		if a == b:
			result = find_result(cnt)
		else:
			result = -1
	print(result)


for _ in range(int(input())):
	(a, b) = list(map(int, input().split()))
	moves = 0
	if a > b:
		(a, b) = (b, a)
	hila = 0
	na = 0
	while a != b:
		hila = 0
		for i in [8, 4, 2]:
			if a * i <= b:
				a = a * i
				moves += 1
				hila = 1
				break
		if hila == 0:
			na = 1
			break
	if na == 1:
		print(-1)
	else:
		print(moves)


import math
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
		continue
	if a < b:
		(a, b) = (b, a)
	c = 0
	flag = 1
	while a != b:
		if a % 8 == 0 and a // 8 >= b:
			a //= 8
			c += 1
		elif a % 4 == 0 and a // 4 >= b:
			a //= 4
			c += 1
		elif a % 2 == 0 and a // 2 >= b:
			c += 1
			a //= 2
		else:
			print(-1)
			flag = 0
			break
	if flag == 1:
		if c != 0:
			print(c)
		else:
			print(-1)


t = int(input())
for i in range(t):
	(x, b) = list(map(int, input().split()))
	operations = 0
	if x > b:
		(x, b) = (b, x)
	count = 0
	if x != b:
		while b > x:
			x *= 2
			operations += 1
			if b == x:
				break
			if b < x:
				operations = -1
				count = -1
				break
		if operations != -1:
			count += operations // 3
			operations %= 3
			count += operations // 2
			operations %= 2
			count += operations
	else:
		count = 0
	print(count)


t = int(input())
while t > 0:
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	count = 0
	while a < b:
		count += 1
		a *= 2
	res = -1
	if a == b:
		res = count // 3
		if count % 3 != 0:
			res += 1
	print(res)
	t -= 1


from math import log

def ispowerof2(num):
	if num & num - 1 == 0:
		return 1
	return 0
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if b >= a:
		if b % a == 0 and ispowerof2(b // a):
			x = int(log(b // a, 2))
			count = 0
			while x > 0:
				if x >= 3:
					count += 1
					x -= 3
				elif x == 2:
					count += 1
					x -= 2
				elif x == 1:
					count += 1
					x -= 1
			print(count)
		else:
			print(-1)
	elif a % b == 0 and ispowerof2(a // b):
		x = int(log(a // b, 2))
		count = 0
		while x > 0:
			if x >= 3:
				count += 1
				x -= 3
			elif x == 2:
				count += 1
				x -= 2
			elif x == 1:
				count += 1
				x -= 2
		print(count)
	else:
		print(-1)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
		continue
	(a, b) = (max(a, b), min(a, b))
	if a % b != 0:
		print(-1)
		continue
	val = a // b
	cnt = 0
	while val % 8 == 0:
		cnt += 1
		val //= 8
	while val % 4 == 0:
		cnt += 1
		val //= 4
	while val % 2 == 0:
		cnt += 1
		val //= 2
	if val == 1:
		print(cnt)
	else:
		print(-1)


t = int(input())
while t > 0:
	try:
		ans = 0
		(a, b) = map(int, input().split())
		if b < a:
			(a, b) = (b, a)
		while a < b:
			a *= 2
			ans += 1
		if a != b:
			print(-1)
		else:
			print(int(ans / 3 + min(ans % 3, 1)))
		t -= 1
	except:
		break


from math import log2

def getR(a):
	while a % 2 == 0:
		a //= 2
	return a
for i in range(int(input())):
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	r = getR(a)
	if getR(b) != r:
		print(-1)
		continue
	ans = 0
	b /= a
	while b >= 8:
		b /= 8
		ans += 1
	if b > 1:
		ans += 1
	print(ans)


def main():
	for _ in range(int(input())):
		n = list(map(int, input().split()))
		(a, b) = (max(n), min(n))
		ans = 0
		while b < a:
			b = b * 8
			ans += 1
		print(ans if a == b or b // 4 == a or b // 2 == a else -1)
main()


import math
from math import *
t = int(input())

def f(a):
	i = 0
	while a != 1:
		if a % 2 == 0:
			a = a // 2
			i += 1
		else:
			return -1
	return i
for i in range(t):
	(a, b) = map(int, input().split())
	if max(a, b) % min(a, b) != 0:
		print(-1)
	else:
		delta = max(a, b) // min(a, b)
		if a == b:
			print(0)
		elif f(delta) >= 0:
			p = f(delta)
			ans = 0
			ans += p // 3
			p = p % 3
			ans += p // 2
			p = p % 2
			ans += p
			print(ans)
		else:
			print(-1)


import math
n = int(input())
inputs = []
results = []
for i in range(n):
	line = input().split()
	inputs.append([int(line[0]), int(line[1])])

def findRootWith2Factor(n):
	while n % 2 == 0:
		n = n // 2
	return n

def findMinNeddedOperation(n, m):
	a = findRootWith2Factor(n)
	b = findRootWith2Factor(m)
	if a != b:
		return -1
	n = n // a
	m = m // b
	operation = math.log2(max(n, m) // min(n, m))
	return math.ceil(operation / 3)
for i in inputs:
	print(findMinNeddedOperation(i[0], i[1]))


import math
t = int(input())
for j in range(0, t):
	(a, b) = map(int, input().split())
	if b == a:
		print(0)
	else:
		c = 0
		mi = min(a, b)
		ma = max(a, b)
		if ma % mi != 0:
			print(-1)
		else:
			p = ma // mi
			if p % 2 != 0:
				print(-1)
			else:
				while p >= 8 and p % 8 == 0:
					p = p // 8
					c = c + 1
				while p >= 4 and p % 4 == 0:
					p = p // 4
					c = c + 1
				while p >= 2 and p % 2 == 0:
					p = p // 2
					c = c + 1
				if p != 1:
					print(-1)
				else:
					print(c)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print('0')
		continue
	elif a > b:
		(a, b) = (b, a)
	ans = 0
	while a < b:
		a *= 2
		ans += 1
	if a == b:
		p = ans % 3
		if p != 0:
			p = 1
		ans = ans // 3 + p
		print(ans)
	else:
		print('-1')


from math import log2
t = int(input())
for i in range(1, t + 1, 1):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	elif a > b and a % b == 0:
		c = int(a // b)
		f = int(log2(c))
		if int(pow(2, f)) == c:
			x = int(f // 3) + int(f % 3 // 2) + int(f % 3 % 2)
			print(x)
		else:
			print(-1)
	elif a < b and b % a == 0:
		c = int(b // a)
		f = int(log2(c))
		if int(pow(2, f)) == c:
			x = int(f // 3) + int(f % 3 // 2) + int(f % 3 % 2)
			print(x)
		else:
			print(-1)
	else:
		print(-1)


import math
for i in range(int(input())):
	(a, b) = [int(x) for x in input().split()]
	if a > b:
		(a, b) = (b, a)
	c = 0
	while a < b:
		a *= 2
		c += 1
	if a == b:
		print(math.ceil(c / 3))
	else:
		print(-1)


from math import log2
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if b == a:
		print(0)
		continue
	elif b > a:
		if b % a != 0:
			print(-1)
			continue
		c = b // a
	else:
		if a % b != 0:
			print(-1)
			continue
		c = a // b
	if c and (not c & c - 1):
		x = int(log2(c))
		c = 0
		c += x // 3
		x %= 3
		c += x // 2
		x %= 2
		c += x
		if c == 0:
			print(-1)
		else:
			print(c)
	else:
		print(-1)


t = int(input())
for inh in range(0, t):
	(a, b) = map(int, input().split())
	if a % b == 0 or b % a == 0:
		n = a // b + b // a
		ans = True
		steps = 0
		while n > 1 and a != b:
			if n % 8 == 0:
				steps += 1
				n = n // 8
			elif n % 4 == 0:
				steps += 1
				n = n // 4
			elif n % 2 == 0:
				steps += 1
				n = n // 2
			else:
				ans = False
				break
		if ans:
			print(steps)
		else:
			print(-1)
	else:
		print(-1)


import math
from sys import stdin
input = stdin.readline

def solve():
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	elif a > b:
		if a % b != 0:
			print(-1)
		else:
			v = a // b
			c = bin(v)[2:]
			gg = c.count('1')
			if gg > 1:
				print(-1)
				return
			s = len(c) - 1
			d = math.ceil(s / 3)
			print(d)
	elif b % a != 0:
		print(-1)
	else:
		v = b // a
		c = bin(v)[2:]
		gg = c.count('1')
		if gg > 1:
			print(-1)
			return
		s = len(c) - 1
		d = math.ceil(s / 3)
		print(d)
for _ in range(int(input())):
	solve()


class Solution:

	def __init__(self):
		(self.a, self.b) = map(int, input().split())
		self.ans = 0

	def getR(self, a):
		while a % 2 == 0:
			a //= 2
		return a

	def solution(self):
		if self.a > self.b:
			(self.a, self.b) = (self.b, self.a)
		if self.getR(self.b) != self.getR(self.a):
			print(-1)
			return
		self.b //= self.a
		while self.b > 8:
			self.b //= 8
			self.ans += 1
		if self.b > 1:
			self.ans += 1
		print(self.ans)

def main():
	for i in range(int(input())):
		ob = Solution()
		ob.solution()
main()


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
import math

def gift():
	for _ in range(t):
		(a, b) = list(map(int, input().split()))
		if a == b:
			yield 0
		else:
			if a > b:
				c = a // b
				d = a % b
			else:
				c = b // a
				d = b % a
			if d:
				yield (-1)
			else:
				dude = math.log(c, 2)
				revdude = 2 ** int(dude)
				if abs(c - revdude) <= 0.1 ** 10:
					e = math.log(c, 8)
					d = 8 ** int(e)
					if abs(d - c) < 0.1 ** 10:
						yield int(e)
					else:
						yield (int(e) + 1)
				else:
					yield (-1)
t = int(input())
ans = gift()
print(*ans, sep='\n')


import math
for i in range(int(int(input()))):
	(a, b) = map(int, input().split())
	(x, y) = (0, 0)
	while a % 2 == 0:
		a = a // 2
		x += 1
	while b % 2 == 0:
		b = b // 2
		y += 1
	if a != b:
		print(-1)
	else:
		print(math.ceil(abs(x - y) / 3))


def checkPower(x):
	pow = 0
	while x > 1:
		if x % 8 == 0:
			pow += 1
			x = x // 8
		elif x % 4 == 0:
			pow += 1
			x = x // 4
		elif x % 2 == 0:
			pow += 1
			x = x // 2
		else:
			return -1
	return pow
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	elif max(a, b) % min(a, b) != 0:
		print(-1)
	else:
		x = max(a, b) // min(a, b)
		print(checkPower(x))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	count = 0
	flag = 1
	num = max(a, b)
	den = min(a, b)
	if num % den != 0:
		print(-1)
		continue
	elif num == den:
		print(0)
		continue
	else:
		val = num // den
		while val != 1:
			if val % 8 == 0:
				val = val // 8
				count += 1
			elif val % 4 == 0:
				val = val // 4
				count += 1
			elif val % 2 == 0:
				val = val // 2
				count += 1
			else:
				flag = 0
				break
	if flag == 0:
		print(-1)
	else:
		print(count)


import math
q = int(input())
for _ in range(q):
	(x, t) = list(map(int, input().split(' ')))
	if x == t:
		print(0)
	elif x < t:
		count = 0
		temp = t // x
		if x * temp == t and temp & temp - 1 == 0:
			power = int(math.log(temp, 2))
			count += power // 3
			power = power % 3
			count += power // 2
			power = power % 2
			count += power
			print(count)
		else:
			print(-1)
	else:
		flag = False
		count = 0
		temp = x // t
		if t * temp == x and temp & temp - 1 == 0:
			power = int(math.log(temp, 2))
			y = x
			for i in range(power):
				if x & 1 == 1:
					flag = True
					break
				else:
					x = x >> 1
			if flag == False:
				power = int(math.log(temp, 2))
				count += power // 3
				power = power % 3
				count += power // 2
				power = power % 2
				count += power
				print(count)
			else:
				print(-1)
		else:
			print(-1)


t = int(input())
for test in range(t):
	(a, b) = [int(x) for x in input().split()]
	num = max(a, b)
	k = min(a, b)
	count = 0
	if num % k != 0:
		print(-1)
		continue
	while num % 8 == 0 and num // 8 >= k:
		num = num // 8
		count += 1
	while num % 4 == 0 and num // 4 >= k:
		num = num // 4
		count += 1
	while num % 2 == 0 and num // 2 >= k:
		num = num // 2
		count += 1
	if num == k:
		print(count)
	else:
		print(-1)


testy = int(input())
results = []
for i in range(testy):
	(a, b) = map(int, input().split())
	if a == b:
		results.append(0)
	elif a > b:
		wyk = 0
		tmp = a
		while tmp > b:
			if tmp % 2 == 0:
				tmp = tmp // 2
				wyk += 1
			else:
				break
		op = [0, 0, 0]
		op[0] = wyk // 3
		op[1] = (wyk - 3 * op[0]) // 2
		op[2] = wyk - 3 * op[0] - 2 * op[1]
		if tmp == b:
			results.append(sum(op))
		else:
			results.append(-1)
	elif b > a:
		wyk = 0
		tmp = b
		while tmp > a:
			if tmp % 2 == 0:
				tmp = tmp // 2
				wyk += 1
			else:
				break
		op = [0, 0, 0]
		op[0] = wyk // 3
		op[1] = (wyk - 3 * op[0]) // 2
		op[2] = wyk - 3 * op[0] - 2 * op[1]
		if tmp == a:
			results.append(sum(op))
		else:
			results.append(-1)
for result in results:
	print(result)


from sys import stdin, stdout
from collections import Counter

def ai():
	return list(map(int, stdin.readline().split()))

def ei():
	return map(int, stdin.readline().split())

def ip():
	return int(stdin.readline().strip())

def op(ans):
	return stdout.write(str(ans) + '\n')
for i in range(ip()):
	(a, b) = ei()
	if a > b:
		(a, b) = (b, a)
	if a == b:
		print(0)
	else:
		c = 0
		while a < b:
			if a * 8 <= b:
				a *= 8
			elif a * 4 <= b:
				a *= 4
			else:
				a *= 2
			c += 1
		print(c if a == b else -1)


from fractions import Fraction
import bisect
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
from queue import Queue

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
mod = int(1000000000.0) + 7

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
t = 1
t = iinput()
for _ in range(t):
	(a, b) = rinput()
	if a > b:
		(a, b) = (b, a)
	ans = 0
	flag = False
	while a < b and b % 8 == 0:
		b = b // 8
		if b < a:
			b = b * 8
			break
		ans += 1
	if a == b:
		print(ans)
		continue
	while a < b and b % 4 == 0:
		b = b // 4
		if b < a:
			b = b * 4
			break
		ans += 1
	if a == b:
		print(ans)
		continue
	while a < b and b % 2 == 0:
		b = b // 2
		if b < a:
			b = b * 2
			break
		ans += 1
	if a == b:
		print(ans)
		continue
	print(-1)


def getR(a):
	while a % 2 == 0:
		a //= 2
	return a

def solve():
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	if getR(a) != getR(b):
		print(-1)
		return
	ans = 0
	b //= a
	while b >= 8:
		b //= 8
		ans += 1
	if b > 1:
		ans += 1
	print(ans)
t = int(input())
for _ in range(t):
	solve()


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	count = 0
	if a == 0 or b == 0:
		print(-1)
		continue
	c = a // b if a > b else b // a
	while c % 8 == 0:
		c //= 8
		count += 1
	while c % 4 == 0:
		c //= 4
		count += 1
	while c % 2 == 0:
		c //= 2
		count += 1
	ans = count if count and c == 1 and (a % b == 0 or b % a == 0) or a == b else -1
	print(ans)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	cnt = 0
	if a > b:
		z = a
		a = b
		b = z
	while b > a * 4 and b != a:
		a *= 8
		cnt += 1
	while b > a * 2 and b != a:
		a *= 4
		cnt += 1
	while b > a and b != a:
		a *= 2
		cnt += 1
	if b == a:
		print(cnt)
	else:
		print(-1)


import math
for i in range(int(input())):
	(a, b) = [int(k) for k in input().split()]
	ans = 0
	if a > b:
		pass
	elif b > a:
		(a, b) = (b, a)
	else:
		print(0)
		continue
	while a % 2 == 0 and a > b:
		a //= 2
		ans += 1
	if a == b:
		print(math.ceil(ans / 3))
	else:
		print(-1)


t = int(input())
for q in range(t):
	(a, b) = map(int, input().split())
	(a, b) = (max(a, b), min(a, b))
	x = a // b
	if a == b:
		print(0)
	elif a % b == 0 and x % 2 == 0:
		if x in (2, 4, 8):
			print(1)
		else:
			c = 0
			while x >= 2:
				if x % 8 == 0:
					x //= 8
				elif x % 4 == 0:
					x //= 4
				elif x % 2 == 0:
					x //= 2
				else:
					c = -1
					break
				c += 1
			print(c)
	else:
		print(-1)


def solve(a, b):
	cnt = 0
	remain = 0
	if a < b:
		(a, b) = (b, a)
	if a == b:
		print(0)
		return
	if a % 2 != 0:
		print(-1)
		return
	while a > b:
		if b << 3 <= a:
			b = b << 3
			cnt += 1
		elif b << 2 <= a:
			b = b << 2
			cnt += 1
		elif b << 1 <= a:
			b = b << 1
			cnt += 1
		else:
			print(-1)
			return
		if a == b:
			print(cnt)
			return
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	solve(a, b)


t = int(input())
for i in range(t):
	(a, b) = [int(k) for k in input().split()]
	if b >= a:
		res = 0
		while b > a:
			a *= 2
			res += 1
		if a != b:
			print(-1)
		else:
			print(res // 3 + int(bool(res % 3)))
	elif a >= b:
		res = 0
		while a > b:
			b *= 2
			res += 1
		if a != b:
			print(-1)
		else:
			print(res // 3 + int(bool(res % 3)))


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	(a, b) = (bin(a), bin(b))
	n = len(b) - len(a)
	x = b[:len(a)]
	y = b[len(a):]
	if x != a or '1' in y:
		print(-1)
	else:
		print(n // 3 + (0 if n % 3 == 0 else 1))


for __ in range(int(input())):
	(a, b) = [int(_) for _ in input().split()]
	(a, b) = (max(a, b), min(a, b))
	ops = 0
	while a % 8 == 0 and a >> 3 >= b:
		a = a >> 3
		ops += 1
	while a % 4 == 0 and a >> 2 >= b:
		a = a >> 2
		ops += 1
	while a % 2 == 0 and a >> 1 >= b:
		a = a >> 1
		ops += 1
	print(ops if a == b else -1)


def solve():
	(a, b) = [int(v) for v in input().split()]
	(a, b) = (min(a, b), max(a, b))
	moves = 0
	while a < b:
		a *= 2
		moves += 1
	if a != b:
		print(-1)
		return
	lastmove = min(moves % 3, 1)
	print(moves // 3 + lastmove)
t = int(input())
for _ in range(t):
	solve()


ans = ''
for _ in range(int(input())):
	cnt = 0
	(a, b) = map(int, input().split())
	if a == b:
		cnt = 0
	elif a < b:
		flag = False
		while a < b:
			if a * 8 <= b:
				a = a * 8
				cnt += 1
			elif a * 4 <= b:
				a = a * 4
				cnt += 1
			elif a * 2 <= b:
				a = a * 2
				cnt += 1
			else:
				break
	elif a > b:
		flag = False
		while a > b:
			if a % 8 == 0 and a // 8 >= b:
				a = a // 8
				cnt += 1
				flag = True
			elif a % 4 == 0 and a // 4 >= b:
				a = a // 4
				cnt += 1
				flag = True
			elif a % 2 == 0 and a // 2 >= b:
				a = a // 2
				cnt += 1
				flag = True
			else:
				break
	if a == b:
		print(str(cnt))
	else:
		print('-1')


for i1 in range(int(input())):
	(a, b) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	if a == b:
		print(0)
		continue
	if b % a != 0:
		print(-1)
		continue
	else:
		b = b // a
		c = 0
		flag = 0
		while True:
			if b == 1:
				flag = 1
				break
			elif b % 8 == 0 and b >= 8:
				b = b // 8
				c += 1
			elif b % 4 == 0 and b >= 4:
				b = b // 4
				c += 1
			elif b % 2 == 0 and b >= 2:
				b = b // 2
				c += 1
			else:
				break
		if flag == 1:
			print(c)
		else:
			print(-1)


import math
from sys import stdin, stdout
from heapq import heapify, heappop, heappush
T = int(stdin.readline())
for i in range(T):
	(a, b) = list(map(int, stdin.readline().split()))
	if a == b:
		print(0)
		continue
	stp = 0
	f = 0
	if a < b:
		while a < b:
			stp += 1
			if a << 3 <= b:
				a = a << 3
			elif a << 2 <= b:
				a = a << 2
			else:
				a = a << 1
			if a == b:
				f = 1
				print(stp)
		if not f:
			print(-1)
	else:
		while a > b:
			stp += 1
			if a % 8 == 0 and a // 8 >= b:
				a = a >> 3
			elif a % 4 == 0 and a // 4 >= b:
				a = a >> 2
			elif a % 2 == 0:
				a = a >> 1
			else:
				f = 1
				print(-1)
				break
			if a == b:
				f = 1
				print(stp)
		if not f:
			print(-1)


for tc in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	else:
		if b > a:
			(a, b) = (b, a)
		bin_a = bin(a)[2:]
		la = len(bin_a)
		bin_b = bin(b)[2:]
		lb = len(bin_b)
		ans = 0
		flag = 1
		index = bin_a.find(bin_b)
		if index > 0 or index == -1:
			print(-1)
		else:
			residue = bin_a[lb:][::-1]
			while residue != '':
				if residue.find('000') == 0:
					ans += 1
					residue = residue[3:]
				elif residue.find('00') == 0:
					ans += 1
					residue = residue[2:]
				elif residue[0] == '0':
					ans += 1
					residue = residue[1:]
				else:
					flag = -1
					break
			if flag == -1:
				print(-1)
			else:
				print(ans)


def log2(x):
	n = 1
	i = 0
	while n < x:
		n *= 2
		i += 1
	if n == x:
		return i
	else:
		return 0.5
t = int(input())
for i in range(t):
	(a, b) = tuple((int(j) for j in input().split()))
	if a == b:
		print(0)
		continue
	if a == 0 or b == 0:
		print(-1)
		continue
	if a % b != 0 and b % a != 0:
		print(-1)
		continue
	if a > b:
		x = log2(a // b)
		if x % 1 == 0:
			print((x + 2) // 3)
			continue
		else:
			print(-1)
			continue
	if b > a:
		x = log2(b // a)
		if x % 1 == 0:
			print((x + 2) // 3)
			continue
		else:
			print(-1)
			continue


import math
t = int(input())
for w in range(t):
	(a, b) = (int(i) for i in input().split())
	c = 0
	k1 = max(a, b)
	k2 = min(a, b)
	while k1 > k2:
		if k1 % 8 == 0 and k1 // 8 >= k2:
			c += 1
			k1 //= 8
		elif k1 % 4 == 0 and k1 // 4 >= k2:
			c += 1
			k1 //= 4
		elif k1 % 2 == 0 and k1 // 2 >= k2:
			c += 1
			k1 //= 2
		else:
			c = -1
			break
	if k1 != k2:
		c = -1
	print(c)


t = int(input())
for x in range(t):
	(a, b) = map(int, input().split())
	y = bin(a)
	z = bin(b)
	if z.find(y) != -1:
		invalid = False
		i = 0
		for x in range(z.index(y) + len(y), len(z)):
			if z[x] == '1':
				invalid = True
				break
			i += 1
		if invalid:
			print(-1)
		else:
			print((i + 2) // 3)
	elif y.find(z) != -1:
		invalid = False
		i = 0
		for x in range(y.index(z) + len(z), len(y)):
			if y[x] == '1':
				invalid = True
				break
			i += 1
		if invalid:
			print(-1)
		else:
			print((i + 2) // 3)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	count_1 = 0
	while a % 2 == 0:
		a //= 2
		count_1 += 1
	count_2 = 0
	while b % 2 == 0:
		b //= 2
		count_2 += 1
	if a != b:
		print(-1)
	else:
		diff = abs(count_1 - count_2)
		answer = diff // 3 + (1 if diff % 3 > 0 else 0)
		print(answer)


import math
T = int(input())
for test in range(1, T + 1):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	else:
		if b < a:
			(a, b) = (b, a)
		(ba, bb) = (bin(a), bin(b))
		ok = True
		for i in range(len(ba)):
			if ba[i] != bb[i]:
				print(-1)
				ok = False
				break
		if ok:
			if all([c == '0' for c in bb[len(ba):]]):
				rem = len(bb) - len(ba)
				print(rem // 3 + (rem % 3 > 0))
			else:
				print(-1)


from math import ceil
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	qtd = 0
	if a > b:
		while a > b:
			if a % 2 != 0:
				break
			a = a // 2
			qtd += 1
		if a == b:
			print(ceil(qtd / 3))
		else:
			print(-1)
	elif a < b:
		while a < b:
			a = a * 2
			qtd += 1
		if a == b:
			print(ceil(qtd / 3))
		else:
			print(-1)
	else:
		print(0)


import math
for z in range(int(input())):
	(a, b) = map(int, input().split())
	c = max(a, b)
	d = min(a, b)
	i = 0
	while d < c:
		i += 1
		d *= 2
	if c == d:
		print(math.ceil(i / 3))
	else:
		print(-1)


ans = []
for _ in range(int(input())):
	(a, b) = list(map(int, input().split()))
	(a, b) = (max(a, b), min(a, b))
	if a % b != 0:
		ans.append(-1)
		continue
	x = a // b
	cnt = 0
	while x % 2 == 0:
		x //= 2
		cnt += 1
	if x != 1:
		ans.append(-1)
		continue
	ansi = (cnt - 1) // 3 + 1
	ans.append(ansi)
print('\n'.join(map(str, ans)))


num = int(input())
for i in range(num):
	(a, b) = [int(j) for j in input().split()]
	m = max(a, b)
	n = min(a, b)
	if m % n != 0:
		print(-1)
	else:
		t = m // n
		counter = 0
		while t > 1:
			if t % 8 == 0:
				t = t // 8
				counter += 1
			elif t % 4 == 0:
				t = t // 4
				counter += 1
			elif t % 2 == 0:
				t = t // 2
				counter += 1
			else:
				counter = -1
				break
		print(counter)


t = int(input())
for _ in range(t):
	(a, b) = list(map(int, input().split()))
	(a, b) = [max(a, b), min(a, b)]
	if a % b == 0:
		ans = 0
		x = a // b
		while x != 1:
			if x % 8 == 0:
				x = x // 8
			elif x % 4 == 0:
				x = x // 4
			elif x % 2 == 0:
				x = x // 2
			else:
				break
			ans += 1
		if x != 1:
			print(-1)
		else:
			print(ans)
	else:
		print(-1)


t = int(input())
while t > 0:
	t = t - 1
	(e, d) = map(int, input().split())
	if e == d:
		print(0)
	else:
		if d > e:
			b = d
			a = e
		else:
			b = e
			a = d
		c = 0
		while b % 2 == 0 and b > a:
			b = b // 2
			c = c + 1
		if b == a:
			f = 2 ** c
			g = 0
			while f % 2 == 0:
				if f % 8 == 0:
					g = g + 1
					f = f // 8
				elif f % 4 == 0:
					g = g + 1
					f = f // 4
				else:
					g = g + 1
					f = f // 2
			print(g)
		else:
			print(-1)


t = int(input())
for x in range(t):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	p = max(a, b)
	q = min(a, b)
	d = 0
	ans = 0
	while q < p:
		q = q * 2
		d += 1
	if p == q:
		while d >= 3:
			d -= 3
			ans += 1
		if d == 2:
			d -= 2
			ans += 1
		if d == 1:
			d -= 1
			ans += 1
		print(ans)
	else:
		ans = -1
		print(ans)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split(' '))
	if a > b:
		(a, b) = (b, a)
	if b % a != 0:
		print(-1)
	else:
		d = b // a
		p = 0
		bad = False
		while d > 1:
			if d % 2 != 0:
				bad = True
				break
			d //= 2
			p += 1
		if bad:
			print(-1)
			continue
		ans = (p + 2) // 3
		print(ans)


cases = int(input())
for t in range(0, cases):
	div = True
	twoCount = 0
	fourCount = 0
	eightCount = 0
	ans = 0
	(a, b) = [int(i) for i in input().split()]
	if b > a:
		if b % a != 0:
			div = False
		else:
			while a < b:
				a = a * 2
				twoCount += 1
				if twoCount == 3:
					eightCount += 1
					twoCount = 0
			if a == b:
				if twoCount == 1 or twoCount == 2:
					ans = eightCount + 1
				else:
					ans = eightCount
			else:
				div = False
	elif b < a:
		if a % b != 0:
			div = False
		else:
			while b < a:
				b = b * 2
				twoCount += 1
				if twoCount == 3:
					eightCount += 1
					twoCount = 0
			if a == b:
				if twoCount == 1 or twoCount == 2:
					ans = eightCount + 1
				else:
					ans = eightCount
			else:
				div = False
	else:
		ans = 0
	if div:
		print(ans)
	else:
		print('-1')


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	cnt = 0
	cnt1 = 0
	while a % 2 == 0:
		cnt += 1
		a //= 2
	while b % 2 == 0:
		cnt1 += 1
		b //= 2
	if a != b:
		print(-1)
	else:
		val = abs(cnt - cnt1)
		ans = 0
		ans += val // 3
		val -= val // 3 * 3
		ans += val // 2
		val -= val // 2 * 2
		ans += val
		print(int(ans))


import sys
input = lambda : sys.stdin.readline().strip()
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = bin(n)
	b = bin(x)
	if a.count('1') != b.count('1'):
		print(-1)
	elif n > x:
		c = 0
		while n > x and n % 2 == 0:
			n >>= 1
			c += 1
		if n == x:
			res = 0
			res += c // 3
			c -= c // 3 * 3
			res += c // 2
			c -= c // 2 * 2
			res += c
			print(res)
		else:
			print(-1)
	else:
		c = 0
		while n < x:
			n <<= 1
			c += 1
		if n == x:
			res = 0
			res += c // 3
			c -= c // 3 * 3
			res += c // 2
			c -= c // 2 * 2
			res += c
			print(res)
		else:
			print(-1)


import sys
lines = []
for line in sys.stdin:
	if 'Exit' == line.rstrip():
		break
	lines.append(line)
t = int(lines[0])
for i in range(1, t + 1):
	(a, b) = ([int(x) for x in lines[i].split(' ')][0], [int(x) for x in lines[i].split(' ')][1])
	if a == b:
		print(0)
		continue
	if a % b != 0 and b % a != 0:
		print(-1)
		continue
	if a % 2 != 0 and b == 1 or (b % 2 != 0 and a == 1):
		print(-1)
		continue
	seen = set()
	seen.add(a)
	seen.add(b)
	copy = a
	ops = 0
	if copy > b:
		(copy, b) = (b, copy)
	while copy * 8 <= b:
		copy *= 8
		ops += 1
		seen.add(copy)
	while copy * 4 <= b:
		copy *= 4
		ops += 1
		seen.add(copy)
	while copy * 2 <= b:
		copy *= 2
		ops += 1
		seen.add(copy)
	if copy == b:
		print(ops)
		continue
	while copy % 8 == 0 and copy // 8 >= b and (copy // 8 not in seen):
		copy //= 8
		ops += 1
		seen.add(copy)
	while copy % 4 == 0 and copy // 4 >= b and (copy // 4 not in seen):
		copy //= 4
		ops += 1
		seen.add(copy)
	while copy % 2 == 0 and copy // 2 >= b and (copy // 2 not in seen):
		copy //= 2
		ops += 1
		seen.add(copy)
	if copy == b:
		print(ops)
		continue
	print(-1)


import sys, io, os, time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect, math, heapq
alphabet = 'abcdefghijklmnopqrstuvwxyz'
input = sys.stdin.readline
for ii in range(int(input())):
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	cnt = 0
	while a < b:
		if a * 8 <= b:
			a = a * 8
		elif a * 4 <= b:
			a = a * 4
		else:
			a = a * 2
		cnt += 1
	if a == b:
		print(cnt)
	else:
		print(-1)


t = int(input())
for k in range(t):
	count = 0
	(a, b) = map(int, input().split())
	if max(a, b) % min(a, b) == 0:
		oper = max(a, b) // min(a, b)
		if oper == 1:
			print(0)
		elif oper & oper - 1:
			print(-1)
		else:
			while oper != 1:
				oper //= 2
				count += 1
			print(count // 3 + count % 3 // 2 + count % 3 % 2 // 1)
	else:
		print(-1)


def isPowerOfTwo(n):
	count = 0
	if n == 0:
		return 0
	while n != 1:
		if n % 2 != 0:
			return 0
		n = n // 2
		count += 1
	return count
t = int(input())
for i in range(t):
	count = 0
	(a, b) = map(int, input().split())
	if b == a:
		print('0')
	else:
		r = max(a, b)
		p = min(a, b)
		if r % p != 0:
			print('-1')
		else:
			x = r // p
			y = isPowerOfTwo(x)
			if y == 0:
				print('-1')
			else:
				count += y // 3
				y = y % 3
				count += y // 2
				y = y % 2
				count += y // 1
				y = y % 1
				print(count)


q = int(input())
for _ in range(q):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	elif a > b:
		c = 0
		f = False
		while a > b:
			if a % 2:
				f = True
				break
			else:
				a //= 2
				c += 1
		if f or a != b:
			print(-1)
			continue
		ans = c // 3
		c %= 3
		ans += c // 2 + c % 2
		print(ans)
	else:
		(a, b) = (b, a)
		c = 0
		f = False
		while a > b:
			if a % 2:
				f = True
				break
			else:
				a //= 2
				c += 1
		if f or a != b:
			print(-1)
			continue
		ans = c // 3
		c %= 3
		ans += c // 2 + c % 2
		print(ans)


import sys
import math
from collections import defaultdict

def solve(test):
	(a, b) = map(int, input().split())
	if b < a:
		if a % b == 0:
			r = a // b
			c = 0
			while r != 1:
				c += 1
				if r % 8 == 0:
					r //= 8
				elif r % 4 == 0:
					r //= 4
				elif r % 2 == 0:
					r //= 2
				else:
					print(-1)
					return
			print(c)
		else:
			print(-1)
	elif a < b:
		if b % a == 0:
			r = b // a
			c = 0
			while r != 1:
				c += 1
				if r % 8 == 0:
					r //= 8
				elif r % 4 == 0:
					r //= 4
				elif r % 2 == 0:
					r //= 2
				else:
					print(-1)
					return
			print(c)
		else:
			print(-1)
	else:
		print(0)
test_cases = int(input())
for t in range(1, test_cases + 1):
	solve(t)


def getR(a):
	while a % 2 == 0:
		a = a // 2
	return a
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a > b:
		temp = a
		a = b
		b = temp
	if getR(b) != getR(a):
		print(-1)
		continue
	ans = 0
	b = b // a
	while b >= 8:
		b = b // 8
		ans += 1
	if b > 1:
		ans += 1
		print(ans)
	else:
		print(ans)


q = int(input())
for i in range(q):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	count = 0
	if a == b:
		print('0')
	elif a > b:
		while b < a:
			if b * 8 <= a:
				b *= 8
				count += 1
			elif b * 4 <= a:
				b *= 4
				count += 1
			else:
				b *= 2
				count += 1
		if b > a:
			print('-1')
		else:
			print(count)
	elif b > a:
		while a < b:
			if a * 8 <= b:
				a *= 8
				count += 1
			elif a * 4 <= b:
				a *= 4
				count += 1
			else:
				a *= 2
				count += 1
		if a > b:
			print('-1')
		else:
			print(count)


import sys
k = int(sys.stdin.readline())
ans = []
for kek in range(k):
	(a, b) = map(int, sys.stdin.readline().split())
	if a == b:
		ans.append(0)
		continue
	if b > a:
		(a, b) = (b, a)
	kek = 0
	while a % 8 == 0 and a // 8 >= b:
		a //= 8
		kek += 1
	while a % 4 == 0 and a // 4 >= b:
		a //= 4
		kek += 1
	while a % 2 == 0 and a // 2 >= b:
		a //= 2
		kek += 1
	if a != b:
		ans.append(-1)
	else:
		ans.append(kek)
print(*ans, sep='\n')


__multitest__ = True

def solve():
	(a, b) = map(int, input().split())
	(a, b) = (max(a, b), min(a, b))
	if a % b != 0:
		print(-1)
	else:
		k = a // b
		ans = 0
		while k > 1:
			if k % 8 == 0:
				k //= 8
			elif k % 4 == 0:
				k //= 4
			elif k % 2 == 0:
				k //= 2
			else:
				print(-1)
				return
			ans += 1
		print(ans)
t = 1 if not __multitest__ else int(input())
for tt in range(t):
	solve()


import sys, bisect, string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
from itertools import permutations, combinations, groupby
rep = range

def Golf():
	(n, *t) = map(int, open(0).read().split())

def I():
	return int(input())

def S_():
	return input()

def IS():
	return input().split()

def LS():
	return [i for i in input().split()]

def LI():
	return [int(i) for i in input().split()]

def LI_():
	return [int(i) - 1 for i in input().split()]

def NI(n):
	return [int(input()) for i in range(n)]

def NI_(n):
	return [int(input()) - 1 for i in range(n)]

def StoLI():
	return [ord(i) - 97 for i in input()]

def ItoS(n):
	return chr(n + 97)

def LtoS(ls):
	return ''.join([chr(i + 97) for i in ls])

def RA():
	return map(int, open(0).read().split())

def GI(V, E, ls=None, Directed=False, index=1):
	org_inp = []
	g = [[] for i in range(V)]
	FromStdin = True if ls == None else False
	for i in range(E):
		if FromStdin:
			inp = LI()
			org_inp.append(inp)
		else:
			inp = ls[i]
		if len(inp) == 2:
			(a, b) = inp
			c = 1
		else:
			(a, b, c) = inp
		if index == 1:
			a -= 1
			b -= 1
		aa = (a, c)
		bb = (b, c)
		g[a].append(bb)
		if not Directed:
			g[b].append(aa)
	return (g, org_inp)

def GGI(h, w, search=None, replacement_of_found='.', mp_def={'#': 1, '.': 0}, boundary=1):
	mp = [boundary] * (w + 2)
	found = {}
	for i in range(h):
		s = input()
		for char in search:
			if char in s:
				found[char] = (i + 1) * (w + 2) + s.index(char) + 1
				mp_def[char] = mp_def[replacement_of_found]
		mp += [boundary] + [mp_def[j] for j in s] + [boundary]
	mp += [boundary] * (w + 2)
	return (h + 2, w + 2, mp, found)

def TI(n):
	return GI(n, n - 1)

def accum(ls):
	rt = [0]
	for i in ls:
		rt += [rt[-1] + i]
	return rt

def bit_combination(n, base=2):
	rt = []
	for tb in range(base ** n):
		s = [tb // base ** bt % base for bt in range(n)]
		rt += [s]
	return rt

def gcd(x, y):
	if y == 0:
		return x
	if x % y == 0:
		return y
	while x % y != 0:
		(x, y) = (y, x % y)
	return y

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
YN = ['YES', 'NO']
Yn = ['Yes', 'No']
mo = 10 ** 9 + 7
inf = float('inf')
FourNb = [(-1, 0), (1, 0), (0, 1), (0, -1)]
EightNb = [(-1, 0), (1, 0), (0, 1), (0, -1), (1, 1), (-1, -1), (1, -1), (-1, 1)]
compas = dict(zip('WENS', FourNb))
cursol = dict(zip('LRUD', FourNb))
l_alp = string.ascii_lowercase
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
input = lambda : sys.stdin.readline().rstrip()

class Tree:

	def __init__(self, inp_size=None, ls=None, init=True, index=1):
		self.LCA_init_stat = False
		self.ETtable = []
		if init:
			if ls == None:
				self.stdin(inp_size, index=index)
			else:
				self.size = len(ls) + 1
				(self.edges, _) = GI(self.size, self.size - 1, ls, index=index)
		return

	def stdin(self, inp_size=None, index=1):
		if inp_size == None:
			self.size = int(input())
		else:
			self.size = inp_size
		(self.edges, _) = GI(self.size, self.size - 1, index=index)
		return

	def listin(self, ls, index=0):
		self.size = len(ls) + 1
		(self.edges, _) = GI(self.size, self.size - 1, ls, index=index)
		return

	def dfs(self, x, func=lambda pr, prv, nx, dist: prv + dist, root_v=0):
		q = deque([x])
		v = [None] * self.size
		v[x] = root_v
		while q:
			c = q.pop()
			for (nb, d) in self.edges[c]:
				if v[nb] == None:
					q.append(nb)
					v[nb] = func(c, v[c], nb, d)
		return v

	def bfs(self, x, func=lambda pr, prv, nx, dist: prv + dist, root_v=0):
		q = deque([x])
		v = [None] * self.size
		v[x] = root_v
		while q:
			c = q.popleft()
			for (nb, d) in self.edges[c]:
				if v[nb] == None:
					q.append(nb)
					v[nb] = func(c, v[c], nb, d)
		return v

	def parent(self, x):
		return self.dfs(0, func=lambda pr, prv, nx, dist: pr, root_v=-1)

	def topological_sort(self, x):
		tps = []
		q = deque([x])
		v = [None] * self.size
		v[x] = 0
		while q:
			c = q.popleft()
			tps.append(c)
			for (nb, d) in self.edges[c]:
				if v[nb] == None:
					q.append(nb)
					v[nb] = 0
		return tps

	def EulerTour(self, x):
		q = deque()
		q.append(x)
		self.depth = [None] * self.size
		self.depth[x] = 0
		self.ETtable = []
		self.ETdepth = []
		self.ETin = [-1] * self.size
		self.ETout = [-1] * self.size
		cnt = 0
		while q:
			c = q.pop()
			if c < 0:
				ce = ~c
			else:
				ce = c
				for (nb, d) in self.edges[ce]:
					if self.depth[nb] == None:
						q.append(~ce)
						q.append(nb)
						self.depth[nb] = self.depth[ce] + 1
			self.ETtable.append(ce)
			self.ETdepth.append(self.depth[ce])
			if self.ETin[ce] == -1:
				self.ETin[ce] = cnt
			else:
				self.ETout[ce] = cnt
			cnt += 1
		return

	def LCA_init(self, root):
		self.EulerTour(root)
		self.st = SparseTable(self.ETdepth, init_func=min, init_idl=inf)
		self.LCA_init_stat = True
		return

	def LCA(self, root, x, y):
		if self.LCA_init_stat == False:
			self.LCA_init(root)
		(xin, xout) = (self.ETin[x], self.ETout[x])
		(yin, yout) = (self.ETin[y], self.ETout[y])
		a = min(xin, yin)
		b = max(xout, yout, xin, yin)
		id_of_min_dep_in_et = self.st.query_id(a, b + 1)
		return self.ETtable[id_of_min_dep_in_et]

	def __str__(self):
		return str(self.edges)

	def show(self):
		if all([all([d == 1 for (nd, d) in edge]) for edge in self.edges]):
			print([[nd for (nd, d) in edge] for edge in self.edges])
		else:
			print(self)

class SparseTable:

	def __init__(self, ls, init_func=min, init_idl=float('inf')):
		self.func = init_func
		self.idl = init_idl
		self.size = len(ls)
		self.N0 = self.size.bit_length()
		self.table = [ls[:]]
		self.index = [list(range(self.size))]
		self.lg = [0] * (self.size + 1)
		for i in range(2, self.size + 1):
			self.lg[i] = self.lg[i >> 1] + 1
		for i in range(self.N0):
			tmp = [self.func(self.table[i][j], self.table[i][min(j + (1 << i), self.size - 1)]) for j in range(self.size)]
			tmp_id = [self.index[i][j] if self.table[i][j] == self.func(self.table[i][j], self.table[i][min(j + (1 << i), self.size - 1)]) else self.index[i][min(j + (1 << i), self.size - 1)] for j in range(self.size)]
			self.table += [tmp]
			self.index += [tmp_id]

	def query(self, l, r):
		if r > self.size:
			r = self.size
		N = self.lg[r - l]
		return self.func(self.table[N][l], self.table[N][max(0, r - (1 << N))])

	def query_id(self, l, r):
		if r > self.size:
			r = self.size
		N = self.lg[r - l]
		(a, b) = (self.index[N][l], self.index[N][max(0, r - (1 << N))])
		if self.table[0][a] == self.func(self.table[N][l], self.table[N][max(0, r - (1 << N))]):
			b = a
		return b

	def right_bound(self, pos, x):
		k = (self.size - pos).bit_length()
		for j in range(k)[::-1]:
			nx = pos + (1 << j)
			if nx < n and self.query(pos, nx + 1) <= x:
				pos += 1 << j
		return pos

	def left_bound(self, pos, x):
		k = pos.bit_length()
		for j in range(k)[::-1]:
			nx = pos - (1 << j)
			if 0 <= nx and self.query(nx, pos + 1) <= x:
				pos -= 1 << j
		return pos

	def __str__(self):
		return str(self.table[0])

	def print(self):
		for i in self.table:
			print(*i)
show_flg = False
show_flg = True
ans = 0
for _ in range(int(input())):
	ans = 0
	(a, b) = LI()
	if a > b:
		(a, b) = (b, a)
	if b % a != 0:
		print(-1)
	else:
		x = b // a
		while x % 2 == 0:
			x //= 2
			ans += 1
		if x != 1:
			print(-1)
			continue
		print((ans + 2) // 3)


import sys
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		(a, b) = map(int, input().split())
		x = y = 0
		while a % 2 == 0:
			a //= 2
			x += 1
		while b % 2 == 0:
			b //= 2
			y += 1
		if a != b:
			print('-1')
			continue
		d = abs(x - y)
		ans = 0
		for r in (3, 2, 1):
			ans += d // r
			d %= r
		print(ans)
main()


n = int(input())
for i in range(n):
	ls = list(map(int, input().split(' ')))
	x = ls[0]
	y = ls[1]
	if x > y:
		(x, y) = (y, x)
	suc = 0
	cnt = 0
	if x == y:
		suc = 1
	while x < y:
		x <<= 1
		cnt += 1
		if x == y:
			suc = 1
	if suc == 0:
		print(-1)
	else:
		print(cnt // 3 + cnt % 3 // 2 + cnt % 3 % 2)


def solve(a, b):
	if b > a:
		(a, b) = (b, a)
	if a % b > 0:
		return -1
	c = a // b
	if c & c - 1 > 0:
		return -1
	i = 0
	while c > 1:
		c //= 8
		i += 1
	return i
for T in range(int(input())):
	print(solve(*map(int, input().split())))


t = int(input())
for _ in range(t):
	lst1 = [int(x) for x in input().split()]
	a = max(lst1)
	b = min(lst1)
	c = 0
	while a % 2 == 0:
		if a <= b:
			break
		a = a // 2
		c += 1
	rem1 = c // 3
	c %= 3
	rem2 = c // 2
	c %= 2
	rem3 = c
	if a != b:
		print(-1)
	else:
		print(rem1 + rem2 + rem3)


def bitc(s):
	c = 0
	for x in s:
		if x == '1':
			c += 1
	return c

def fun(s):
	return bin(int(s))[2:]
_ = int(input())
while _ > 0:
	_ -= 1
	(a, b) = map(fun, input().split(' '))
	fa = a.find(b)
	fb = b.find(a)
	la = len(a)
	lb = len(b)
	if bitc(a) != bitc(b):
		print(-1)
		continue
	elif fa == -1 and fb == -1:
		print(-1)
		continue
	elif fa == -1 and fb != -1:
		l = lb - la
		ans = l // 3
		if l % 3 != 0:
			ans += 1
		print(ans)
	elif fa != -1 and fb == -1:
		l = la - lb
		ans = l // 3
		if l % 3 != 0:
			ans += 1
		print(ans)
	else:
		print(0)


import math
tc = int(input())
while True:
	if tc == 0:
		break
	tc = tc - 1
	tmp = input()
	lst = tmp.split(' ')
	a = int(lst[0])
	b = int(lst[1])
	if a >= b:
		tot = 0
		while a % 8 == 0:
			tmp = a // 8
			if tmp < b:
				break
			a = tmp
			tot += 1
		while a % 4 == 0:
			tmp = a // 4
			if tmp < b:
				break
			a = tmp
			tot += 1
		while a % 2 == 0:
			tmp = a // 2
			if tmp < b:
				break
			a = a // 2
			tot += 1
		if a == b:
			print(tot)
		else:
			print(-1)
	else:
		tot = 0
		while a * 8 <= b:
			a = a * 8
			tot += 1
		while a * 4 <= b:
			a = a * 4
			tot += 1
		while a * 2 <= b:
			a = a * 2
			tot += 1
		if a == b:
			print(tot)
		else:
			print(-1)


def PowerOfTwo(x):
	return x and (not x & x - 1)
t = int(input())
while t != 0:
	t -= 1
	(a, b) = map(int, input().split())
	(p, q) = (max(a, b), min(a, b))
	if p % q != 0:
		print(-1)
	else:
		k = p // q
		if k == 1:
			print(0)
		elif PowerOfTwo(k) == False:
			print(-1)
		else:
			ans = 0
			while 2 ** ans <= k:
				ans += 1
			ans -= 1
			m = 0
			m += ans // 3
			ans = ans % 3
			m += ans // 2
			ans = ans % 2
			m += ans
			print(m)


from sys import stdin
import math
a = int(stdin.readline())
for b in range(0, a):
	A = stdin.readline().split()
	MAX = max(int(A[0]), int(A[1]))
	MIN = min(int(A[0]), int(A[1]))
	count = 0
	K = 0
	if MIN == MAX:
		print(0)
		continue
	while MIN < MAX:
		MIN *= 2
		count += 1
		if MIN > MAX:
			print(-1)
			K = 1
			break
	if K == 0:
		if count <= 2:
			print(1)
		elif count % 3 == 0:
			print(int(count / 3))
		else:
			print(int(math.ceil(count / 3)))


for ii in range(int(input())):
	(aa, bb) = map(int, input().split())
	if bb == aa:
		print(0)
	else:
		c = 0
		if bb > aa:
			(aa, bb) = (bb, aa)
		y = aa / bb
		if aa % bb != 0 or y % 2 != 0:
			print(-1)
		else:
			num = bin(aa // bb).replace('0b', '')
			res = [int(x) for x in str(num)]
			x = res.count(0)
			if 2 ** x == y:
				ans = 0
				ans = x // 3
				x = x % 3
				ans += x // 2
				x = x % 2
				ans += x // 1
				print(ans)
			else:
				print(-1)


import sys

def ii():
	return sys.stdin.readline().strip()

def idata():
	return [int(x) for x in ii().split()]

def solve_of_problem():
	(a, b) = [int(x) for x in input().split()]
	(a, b) = (max(a, b), min(a, b))
	count = 0
	if a % 1 != 0:
		print(-1)
		return
	while a > b:
		b *= 2
		count += 1
	if a == b:
		print((count + 2) // 3)
	else:
		print(-1)
	return
for t in range(int(ii())):
	solve_of_problem()


for q in range(int(input())):
	(a, b) = map(int, input().split())
	a1 = bin(a)[2:]
	b1 = bin(b)[2:]
	a2 = ''
	for i in range(len(a1)):
		if a1[i] == '1':
			a2 = a1[i:]
			break
	b2 = ''
	for i in range(len(b1)):
		if b1[i] == '1':
			b2 = b1[i:]
			break
	j1 = 0
	while len(a2) != 0 and a2[-1] == '0':
		j1 += 1
		a2 = a2[:-1]
	j2 = 0
	while len(b2) != 0 and b2[-1] == '0':
		j2 += 1
		b2 = b2[:-1]
	if a2 != b2:
		print(-1)
	else:
		anz = abs(j1 - j2)
		cnt = anz // 3
		anz %= 3
		cnt += anz // 2
		anz %= 2
		cnt += anz
		print(cnt)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	mul = 0
	div = 0
	if a < b:
		while a < b:
			a *= 2
			mul += 1
	else:
		while a > b:
			if a & 1 == 0:
				a = a // 2
				div += 1
			else:
				break
	if a != b:
		print(-1)
		continue
	ans = 0
	ans = mul // 3
	mul = mul % 3
	ans += mul // 2
	mul = mul % 2
	ans += mul
	ans += div // 3
	div = div % 3
	ans += div // 2
	div = div % 2
	ans += div
	print(ans)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a > b:
		ans = 0
		while a > b:
			b *= 2
			ans += 1
		if a == b:
			print((ans + 2) // 3)
		else:
			print(-1)
	elif b > a:
		ans = 0
		while b > a:
			a *= 2
			ans += 1
		if a == b:
			print((ans + 2) // 3)
		else:
			print(-1)
	else:
		print(0)


import math

def inp_n():
	return int(input())

def inp_list():
	return list(map(int, input().split()))

def inp_mul_num():
	return map(int, input().split())

def is_odd(n):
	if n & 1:
		return True
	return False
for _ in range(inp_n()):
	(a, b) = inp_mul_num()
	c = 0
	if a < b:
		(a, b) = (b, a)
	if a == b:
		print(0)
	elif a > b:
		while a > b:
			if a % 8 == 0:
				a //= 8
				c += 1
			elif a % 4 == 0:
				a //= 4
				c += 1
			elif a % 2 == 0:
				a //= 2
				c += 1
			else:
				break
		if a == b:
			print(c)
		elif a * 2 == b or a * 4 == b:
			print(c)
		else:
			print(-1)


z = int(input())
for q in range(z):
	(a, b) = map(int, input().split())
	j = a
	a = max(a, b)
	b = min(j, b)
	if a == b:
		print(0)
	elif a % b != 0:
		print(-1)
	else:
		x = a // b
		cnt = 0
		flag = 0
		while True:
			if x >= 8 and x % 8 == 0:
				x = x // 8
				cnt += 1
			elif x == 4 or x == 2:
				cnt += 1
				break
			elif x == 1:
				break
			else:
				flag = 1
				break
		if flag == 1:
			print(-1)
		else:
			print(cnt)


import io
import os
from collections import Counter, defaultdict, deque

def solve(A, B):
	aPlaces = 0
	while A % 2 == 0:
		A //= 2
		aPlaces += 1
	bPlaces = 0
	while B % 2 == 0:
		B //= 2
		bPlaces += 1
	if A != B:
		return -1
	temp = abs(aPlaces - bPlaces)
	if temp % 3 == 0:
		return temp // 3
	return temp // 3 + 1
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = int(input())
for t in range(T):
	(A, B) = [int(x) for x in input().split()]
	ans = solve(A, B)
	print(ans)


import sys
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def read():
	tc = 0
	if tc:
		input = sys.stdin.readline
	else:
		sys.stdin = open('input1.txt', 'r')
		sys.stdout = open('output1.txt', 'w')

def powermod(a, b, m):
	a %= m
	res = 1
	if a == 0:
		return 0
	while b > 0:
		if b & 1:
			res = res * a % m
		b = b >> 1
		a = a * a % m
	return res

def isprime(n):
	if n <= 1:
		return 0
	for i in range(2, int(sqrt(n)) + 1):
		if n % i == 0:
			return 0
	return 1

def solve():
	for _ in range(ii()):
		(a, b) = mi()
		if a == b:
			print(0)
			continue
		if a < b:
			(a, b) = (b, a)
		(c1, c2, c3) = (0, 0, 0)
		while a % 2 == 0 and a > b:
			a //= 2
			c1 += 1
		if a != b:
			print('-1')
		else:
			ans = c1 // 3
			c1 %= 3
			ans += c1 // 2
			c1 %= 2
			ans += c1
			print(ans)
solve()


for tt in range(int(input())):
	(a, b) = map(int, input().split())
	ans = 0
	if a > b:
		while a > b:
			if not a & 1:
				a = a >> 1
				ans += 1
			else:
				break
	else:
		while b > a:
			a = a << 1
			ans += 1
	if a == b:
		print(ans // 3 + (0 if ans % 3 == 0 else 1))
	else:
		print(-1)


from sys import stdin, stdout
import math
from decimal import *

def main():
	t = int(stdin.readline())
	for ks in range(t):
		(a, b) = list(map(int, stdin.readline().split()))
		(a, b) = (max(a, b), min(a, b))
		if a == b:
			stdout.write('0\n')
			continue
		if a % b != 0 or Decimal(a) / Decimal(b) % 2 != 0:
			stdout.write('-1\n')
			continue
		mul = Decimal(a) / Decimal(b)
		jk = mul
		while jk % 2 == 0:
			jk /= 2
		if jk != 1:
			stdout.write('-1\n')
			continue
		cnt = int(math.log2(mul))
		cnt = math.ceil(cnt / 3)
		stdout.write(str(cnt) + '\n')
main()


for T in range(int(input())):
	(a, b) = list(map(int, input().split()))
	mn = min(a, b)
	mx = max(a, b)
	v = mx // mn
	r = mx % mn
	if r != 0:
		print(-1)
		continue
	count = 0
	while v % 8 == 0:
		count += 1
		v = v // 8
	while v % 4 == 0:
		count += 1
		v = v // 4
	while v % 2 == 0:
		count += 1
		v = v // 2
	if v > 2:
		print(-1)
	else:
		print(count)


match = lambda pattern, string: pattern == string[:len(pattern)]
bstr = lambda number: bin(number)[2:]

def shorten(s):
	n = len(s)
	res = n // 3
	r3 = n % 3
	res += r3 // 2 + r3 % 2
	return res

def solve(a, b):
	if a <= b:
		ba = bstr(a)
		bb = bstr(b)
		if match(ba, bb):
			if not '1' in bb[len(ba):]:
				return shorten(bb[len(ba):])
	else:
		ba = bstr(a)
		bb = bstr(b)
		if match(bb, ba):
			if not '1' in ba[len(bb):]:
				return shorten(ba[len(bb):])
	return -1
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	print(solve(a, b))


for _ in range(int(input())):
	p = []
	for i in range(1, 61):
		p.append(2 ** i)
	l = list(map(int, input().split()))
	l.sort()
	a = l[0]
	b = l[1]
	if a == b:
		print(0)
	elif b % a != 0:
		print(-1)
	else:
		c = b // a
		eight = 0
		while c % 8 == 0:
			c = c // 8
			eight += 1
		four = 0
		while c % 4 == 0:
			c = c // 4
			four += 1
		two = 0
		while c % 2 == 0:
			c = c // 2
			two += 1
		if c == 1:
			print(four + two + eight)
		else:
			print(-1)


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	(a, b) = (bin(a)[2:], bin(b)[2:])
	(la, lb) = (len(a), len(b))
	if la > lb:
		(la, lb) = (lb, la)
		(a, b) = (b, a)
	i = 0
	while i < la:
		if a[i] != b[i]:
			print(-1)
			break
		i += 1
	else:
		if not b[i:]:
			print(0)
		elif b[i:].count('1') == 0:
			t = lb - i
			ans = t // 3 + (1 if t % 3 else 0)
			print(ans)
		else:
			print(-1)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	c = 0
	if n < m:
		while len(bin(n)) < len(bin(m)):
			n = n << 1
			c += 1
	else:
		while len(bin(n)) > len(bin(m)):
			if n % 2 == 1:
				break
			n = n >> 1
			c += 1
	if n == m:
		print(c // 3 + (0, 1)[c % 3 > 0])
	else:
		print(-1)


def get_r(a):
	while a % 2 == 0:
		a //= 2
	return a

def solve():
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	r = get_r(a)
	if get_r(b) != r:
		print('-1')
		return
	count = 0
	b //= a
	while b >= 8:
		b //= 8
		count += 1
	if b > 1:
		count += 1
	print(count)
T = int(input())
while T > 0:
	T -= 1
	solve()


import math
t = int(input())
for test in range(t):
	(a, b) = map(int, input().split())
	ratio = 0
	flag = True
	if a == b:
		print(0)
		continue
	elif a > b:
		if a % b == 0:
			ratio = a // b
		else:
			flag = False
	elif b % a == 0:
		ratio = b // a
	else:
		flag = False
	ans = 0
	while ratio >= 8 and ratio % 8 == 0:
		ratio = ratio // 8
		ans += 1
	while ratio >= 4 and ratio % 4 == 0:
		ratio = ratio // 4
		ans += 1
	while ratio >= 2 and ratio % 2 == 0:
		ratio = ratio // 2
		ans += 1
	if ratio != 1:
		print(-1)
	else:
		print(ans)


t = int(input())
for _ in range(t):
	(x, y) = map(int, input().split())
	ans = 0
	flag = 0
	if x > y:
		while x > y:
			if x / 8 % y == 0:
				x = x // 8
			elif x / 4 % y == 0:
				x = x // 4
			elif x / 2 % y == 0:
				x = x // 2
			else:
				break
			ans += 1
	elif x < y:
		while x < y:
			if y % (x * 8) == 0:
				x = x * 8
			elif y % (x * 4) == 0:
				x = x * 4
			elif y % (x * 2) == 0:
				x = x * 2
			else:
				break
			ans += 1
	if x == y:
		print(ans)
	else:
		print(-1)


for _ in range(int(input())):
	(a, b) = [int(i) for i in input().split()]
	if a == b:
		print(0)
		continue
	if b > a:
		(a, b) = (b, a)
	if a % b != 0:
		print(-1)
	elif a // b & a // b - 1 != 0:
		print(-1)
	else:
		ans = 0
		chastnoe = a // b
		k = 8
		while chastnoe != 1:
			while chastnoe % k != 0:
				k //= 2
			while chastnoe % k == 0:
				chastnoe //= k
				ans += 1
		print(ans)


def get_answer(a, b):
	if a == b:
		return 0
	n_ops = 0
	if a > b:
		while a > b:
			if a % 8 == 0 and a // 8 >= b:
				a //= 8
				n_ops += 1
			elif a % 4 == 0 and a // 4 >= b:
				a //= 4
				n_ops += 1
			elif a % 2 == 0 and a // 2 >= b:
				a //= 2
				n_ops += 1
			else:
				break
		if a == b:
			return n_ops
		else:
			return -1
	if a < b:
		while a < b:
			if b % 8 == 0 and b // 8 >= a:
				b //= 8
				n_ops += 1
			elif b % 4 == 0 and b // 4 >= a:
				b //= 4
				n_ops += 1
			elif b % 2 == 0 and b // 2 >= a:
				b //= 2
				n_ops += 1
			else:
				break
		if a == b:
			return n_ops
		else:
			return -1
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	print(get_answer(a, b))


import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase

def inar():
	return [int(k) for k in input().split()]

def main():
	for _ in range(int(input())):
		(a, b) = map(int, input().split())
		if a == b:
			print(0)
		else:
			if max(a, b) % min(a, b) != 0:
				print(-1)
				continue
			rem = max(a, b) // min(a, b)
			c = 0
			while 1:
				if rem == 1:
					break
				if rem % 8 == 0:
					rem = rem // 8
					c += 1
				elif rem % 4 == 0:
					rem = rem // 4
					c += 1
				elif rem % 2 == 0:
					rem = rem // 2
					c += 1
				elif rem != 1:
					c = -1
					break
				elif rem == 1:
					break
			print(c)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from decimal import *
t = int(input())
getcontext().prec = 80
while t > 0:
	t -= 1
	(a, b) = list(map(Decimal, input().split(' ')))
	c = a
	counter = 0
	while a * 8 <= b:
		counter += 1
		a = a * 8
	while a * 4 <= b:
		counter += 1
		a = a * 4
	while a * 2 <= b:
		counter += 1
		a = a * 2
	while a >= b * 8:
		counter += 1
		a = a / 8
	while a >= b * 4:
		counter += 1
		a = a / 4
	while a >= b * 2:
		counter += 1
		a = a / 2
	if a != b:
		print(-1)
	else:
		print(counter)


for i in range(int(input())):
	(a, b) = [int(x) for x in input().split()]
	maxi = max(a, b)
	mini = min(a, b)
	if maxi == mini:
		print('0')
	elif maxi / mini % 2 != 0:
		print('-1')
	else:
		divisible = maxi // mini
		counterr = 0
		while divisible % 8 == 0:
			counterr += 1
			divisible = divisible // 8
		if divisible == 1:
			print(counterr)
		elif divisible == 2 or divisible == 4:
			print(counterr + 1)
		else:
			print('-1')


import sys
import math
t = int(sys.stdin.readline().strip())
for _ in range(t):
	(a, b) = list(map(int, sys.stdin.readline().strip().split(' ')))
	if a < b:
		(a, b) = (b, a)
	c = '{0:b}'.format(a)
	d = '{0:b}'.format(b)
	if not c.startswith(d):
		print(-1)
	else:
		e = c[len(d):]
		if e == '':
			print(0)
		elif int(e) != 0:
			print(-1)
		else:
			cnt = 0
			n = len(e)
			for i in [3, 2, 1]:
				cnt += n // i
				n = n % i
			print(cnt)


import math
t = int(input())
for _ in range(t):
	(a, b) = list(map(int, input().split()))
	m = min(a, b)
	n = max(a, b)
	if n % m != 0:
		print(-1)
	else:
		x = int(math.log2(n / m))
		if 2 ** x * m == n:
			c = 0
			c = c + x // 3
			x = x % 3
			c = c + x // 2
			x = x % 2
			c = c + x
			print(c)
		else:
			print(-1)


def find(a):
	c = 0
	while a % 2 == 0:
		a = a // 2
		c += 1
	return (a, c)
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	(a, b) = (max(a, b), min(a, b))
	if a == b:
		print(0)
		continue
	(a, c1) = find(a)
	(b, c2) = find(b)
	if a != b:
		print(-1)
	else:
		c = (c1 - c2) // 3
		if (c1 - c2) % 3:
			c += 1
		print(c)


def ok(x):
	while x % 2 == 0:
		x //= 2
	return x
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if b > a:
		c = a
		a = b
		b = c
	r = ok(a)
	r2 = ok(b)
	if r != r2:
		print('-1')
	else:
		ans = 0
		a //= b
		ans = 0
		while a >= 8:
			a //= 8
			ans += 1
		if a > 1:
			ans += 1
		print(ans)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	else:
		i = 1
		flag = 1
		if a > b:
			temp = a
			a = b
			b = temp
		while True:
			if 2 ** i * a < b:
				i += 1
			if 2 ** i * a == b:
				x = i
				break
			if 2 ** i * a > b:
				print(-1)
				flag = 0
				break
		if flag == 1:
			a = x // 3
			x = x - a * 3
			b = x // 2
			x = x - b * 2
			c = x // 1
			print(a + b + c)


import math
N = int(input())
for i in range(N):
	(a, b) = map(int, input().split())
	if b > a:
		(a, b) = (b, a)
	cnt = 0
	while a > b:
		b *= 2
		cnt += 1
	if a == b:
		print(math.ceil(cnt / 3))
	else:
		print(-1)


import sys
import math
from collections import defaultdict, deque
import heapq
t = int(sys.stdin.readline())
for _ in range(t):
	(a, b) = map(int, sys.stdin.readline().split())
	if a == b:
		print(0)
		continue
	if a > b:
		y = 0
		while b < a:
			b = b << 1
			y += 1
		if b != a:
			print(-1)
			continue
		ans = 0
		if y % 3 == 0:
			ans = y // 3
		else:
			ans = y // 3 + 1
		print(ans)
		continue
	y = 0
	while a < b:
		a = a << 1
		y += 1
	if a != b:
		print(-1)
		continue
	ans = 0
	if y % 3 == 0:
		ans = y // 3
	else:
		ans = y // 3 + 1
	print(ans)
	continue


def intlog(num, base):
	n = num
	res = 0
	while n >= base:
		n //= base
		res += 1
	return res
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if b == a:
		print(0)
	elif b > a:
		if b % a == 0 and 2 ** intlog(b // a, 2) == b // a:
			ans = b // a
			p = intlog(ans, 2)
			print(p // 3 + int(p % 3 > 0))
		else:
			print(-1)
	elif a % b == 0 and 2 ** intlog(a // b, 2) == a // b:
		ans = a // b
		p = intlog(ans, 2)
		print(p // 3 + int(p % 3 > 0))
	else:
		print(-1)


t = int(input())
for i in range(t):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	if a > b:
		(a, b) = (b, a)
	counter = 0
	res = 0
	decide = True
	while b != a:
		if b % 2 == 1:
			res = -1
			decide = False
			break
		else:
			b = int(b // 2)
			counter += 1
			if counter == 3:
				res += 1
				counter = 0
	if counter != 0 and decide:
		res += 1
	print(res)


from math import floor, log
import sys
sys.setrecursionlimit(10000)

class Memoize:

	def __init__(self, f):
		self.f = f
		self.memo = {}

	def __call__(self, *args):
		if not args in self.memo:
			self.memo[args] = self.f(*args)
		return self.memo[args]

class Recurse(Exception):

	def __init__(self, *args, **kwargs):
		self.args = args
		self.kwargs = kwargs

def recurse(*args, **kwargs):
	raise Recurse(*args, **kwargs)

def tail_recursive(f):

	def decorated(*args, **kwargs):
		while True:
			try:
				return f(*args, **kwargs)
			except Recurse as r:
				args = r.args
				kwargs = r.kwargs
				continue
	return decorated

def without_twos(x):
	while x % 2 == 0:
		x //= 2
	return x
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a < b:
		(a, b) = (b, a)
	if a == b:
		print(0)
	elif a == 0 or b == 0 or without_twos(a) != without_twos(b):
		print(-1)
	else:
		div = a // b
		ans = 0
		for i in [8, 4, 2]:
			if div == 0:
				break
			num = floor(log(div, i))
			ans += num
			div = div // int(i ** num)
		print(ans)


t = int(input())
for _ in range(0, t):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	elif a > b:
		ans = True
		ss = 0
		while a > b:
			if a % 2 == 0:
				a //= 2
				ss += 1
			elif a != b:
				ans = False
				break
		if ans:
			if a == b:
				eights = ss // 3
				ss -= 3 * eights
				fours = 0
				if ss:
					fours = ss // 2
					ss -= 2 * fours
				print(eights + fours + ss)
			else:
				print(-1)
		else:
			print(-1)
	elif a < b:
		ss = 0
		while a < b:
			a *= 2
			ss += 1
		if a == b:
			eights = ss // 3
			ss -= 3 * eights
			fours = 0
			if ss:
				fours = ss // 2
				ss -= 2 * fours
			print(eights + fours + ss)
		else:
			print(-1)


def kk(x):
	return x and (not x & x - 1)
import math
T = int(input())
for _ in range(0, T):
	(A, B) = map(int, input().split())
	a = min(A, B)
	b = max(A, B)
	if b == a:
		print(0)
	elif b % a != 0:
		print(-1)
	else:
		tt = b // a
		if kk(tt):
			tot = int(math.log2(tt))
			ans = tot // 3
			tot = tot % 3
			if tot != 0:
				ans += 1
			print(ans)
		else:
			print(-1)


tc = int(input().strip())
while tc:
	(a, b) = map(bin, map(int, input().strip().split()))
	(a, b) = (list(a[2:]), list(b[2:]))
	(ai, bi) = (0, 0)
	while ai < len(a) and bi < len(b):
		if a[ai] == b[bi]:
			ai += 1
			bi += 1
		else:
			break
	if ai == len(a) and bi == len(b):
		rem = 0
	elif ai == len(a):
		rem = len(b) - bi if '1' not in b[bi:] else -1
	elif bi == len(b):
		rem = len(a) - ai if '1' not in a[ai:] else -1
	else:
		rem = -1
	if rem == -1:
		ans = rem
	else:
		ans = rem // 3
		if rem % 3 > 0:
			ans += 1
	print(ans)
	tc -= 1


import math
t = int(input())
for _ in range(t):
	(x, y) = [int(x) for x in input().split()]
	c = 0
	if x == y:
		print(0)
	elif x > y:
		if x % y == 0:
			while x != y and x > y:
				if x % 8 == 0 and x // 8 >= y:
					c += 1
					x = x // 8
				else:
					break
			while x != y and x > y:
				if x % 4 == 0 and x // 4 >= y:
					c += 1
					x = x // 4
				else:
					break
			while x != y and x > y:
				if x % 2 == 0 and x // 2 >= y:
					c += 1
					x = x // 2
				else:
					break
			if x == y:
				print(c)
			else:
				print(-1)
		else:
			print(-1)
	elif y > x and y % x == 0:
		while x != y and x < y:
			if x * 8 <= y:
				x = x * 8
				c += 1
			else:
				break
		while x != y and x < y:
			if x * 4 <= y:
				x = x * 4
				c += 1
			else:
				break
		while x != y and x < y:
			if x * 2 <= y:
				x = x * 2
				c += 1
			else:
				break
		if x == y:
			print(c)
		else:
			print(-1)
	else:
		print(-1)


import sys, math
input = sys.stdin.readline

def primeFactors(a, b):
	bina = bin(a)
	binb = bin(b)
	return len(binb) - len(bina)
t = int(input())
for r in range(t):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	else:
		x = min(a, b)
		y = max(a, b)
		b = y
		a = x
		if b % a != 0:
			print(-1)
		else:
			f = b // a
			logx = len(bin(f)) - 3
			if 2 ** logx == f:
				power = primeFactors(a, b)
				q = power // 3
				power = power % 3
				tt = power // 2
				s = power % 2
				print(q + tt + s)
			else:
				print(-1)


def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
n = inp()
for i in range(n):
	l = inlt()
	a = l[0]
	b = l[1]
	f = 1
	count = 0
	while a % 2 == 0:
		count += 1
		a //= 2
	count2 = 0
	while b % 2 == 0:
		count2 += 1
		b //= 2
	if a != b:
		print(-1)
	else:
		dif = abs(count - count2)
		print((dif % 3 != 0) + dif // 3)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	t = 0
	while a < b:
		t += 1
		a = a << 3
	if a == b or a >> 1 == b or a >> 2 == b:
		print(t)
	else:
		print(-1)


A = [1]
for i in range(1, 101):
	A.append(A[-1] * 2)
for _ in range(int(input())):
	(a, b) = sorted(list(map(int, input().split())))
	c = b // a
	if b % a == 0 and c in A:
		i = A.index(c)
		print(i // 3 + i % 3 // 2 + i % 3 % 2)
	else:
		print(-1)


import math
pow_two = {2 ** i: i for i in range(100)}
for z in range(int(input())):
	(a, b) = sorted(list(map(int, input().split())))
	ans = 0
	if b % a == 0:
		if b // a in pow_two:
			print((pow_two[b // a] + 2) // 3)
		else:
			print(-1)
	else:
		print(-1)


import math
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a >= b:
		if a == b:
			print(0)
		else:
			(a, b) = (b, a)
			count = 0
			if b % 2 != 0:
				print(-1)
			else:
				f = 1
				while a < b:
					if 8 * a <= b:
						a = a * 8
						count += 1
					elif 4 * a <= b:
						a = a * 4
						count += 1
					elif a * 2 <= b:
						a = a * 2
						count += 1
					else:
						f = 0
						break
				if f == 1 and a == b:
					print(count)
				else:
					print(-1)
	else:
		count = 0
		if b % 2 != 0:
			print(-1)
		else:
			f = 1
			while a < b:
				if 8 * a <= b:
					a = a * 8
					count += 1
				elif 4 * a <= b:
					a = a * 4
					count += 1
				elif a * 2 <= b:
					a = a * 2
					count += 1
				else:
					f = 0
					break
			if f == 1 and a == b:
				print(count)
			else:
				print(-1)


t = int(input())
for i in range(t):
	a = list(map(int, input().split()))
	ma = max(a[0], a[1])
	mi = min(a[0], a[1])
	if a[0] < a[1]:
		cnt = 0
		while a[0] * 8 <= a[1]:
			a[0] *= 8
			cnt += 1
		while a[0] * 4 <= a[1]:
			a[0] *= 4
			cnt += 1
		while a[0] * 2 <= a[1]:
			a[0] *= 2
			cnt += 1
		if a[0] == a[1]:
			print(cnt)
		else:
			print(-1)
	elif a[0] >= a[1]:
		cnt = 0
		while (a[0] // 8 >= a[1]) & (a[0] % 8 == 0):
			a[0] //= 8
			cnt += 1
		while (a[0] // 4 >= a[1]) & (a[0] % 4 == 0):
			a[0] //= 4
			cnt += 1
		while (a[0] // 2 >= a[1]) & (a[0] % 2 == 0):
			a[0] //= 2
			cnt += 1
		if a[0] == a[1]:
			print(cnt)
		else:
			print(-1)


from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
	return int(input())

def rl():
	return list(map(int, input().split()))

def solve():
	(a, b) = rl()
	moves = 0
	if a <= b:
		while a < b:
			a *= 2
			moves += 1
		if a > b:
			print(-1)
			return
		else:
			print((moves + 2) // 3)
			return
	else:
		while a > b:
			if a % 2 != 0:
				print(-1)
				return
			else:
				a //= 2
				moves += 1
		if a < b:
			print(-1)
			return
		else:
			print((moves + 2) // 3)
			return
mode = 'T'
if mode == 'T':
	t = ri()
	for i in range(t):
		solve()
else:
	solve()


t = int(input())
import math
for _ in range(t):
	(a, b) = map(int, input().split())
	ma = max(a, b)
	mi = min(a, b)
	if a == b:
		print(0)
		continue
	if ma / mi == ma // mi and ma // mi % 2 == 0:
		s = math.log(ma // mi, 2)
		if s == int(s):
			if s % 3 == 0:
				print(int(s // 3))
				continue
			else:
				print(int(s // 3 + 1))
				continue
	print(-1)


tt = int(input())
for z in range(tt):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
		continue
	fa = a
	c = -1
	for i in range(100):
		a = a << 1
		if a == b:
			c = i + 1
			break
	if c != -1:
		print((c + 2) // 3)
		continue
	a = fa
	if a & 1:
		print(-1)
		continue
	c = -1
	for i in range(100):
		a = a >> 1
		if a == b:
			c = i + 1
			break
		if a & 1:
			break
	if c != -1:
		print((c + 2) // 3)
		continue
	print(-1)


for t in range(int(input())):
	(n, m) = map(int, input().split())
	(n, m) = (min(n, m), max(n, m))
	c = 0
	while n < m:
		n *= 8
		c += 1
	if m == n or m == n // 4 or m == n // 2:
		print(c)
	else:
		print(-1)


def two(a):
	i = 0
	yes = False
	while 2 ** i <= a:
		if 2 ** i == a:
			yes = True
			break
		i += 1
	return [yes, i]

def calc(a, b):
	if a > b:
		(a, b) = (b, a)
	q = b // a
	p = two(q)
	if b % a == 0 and p[0]:
		n = p[1]
		x = 0
		x += n // 3
		n %= 3
		x += n // 2
		n %= 2
		x += n
		return x
	else:
		return -1
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	print(calc(a, b))


t = int(input())
for i in range(t):
	c = 0
	(a, b) = map(int, input().split())
	if a > b:
		while a > b:
			if a % 8 == 0 and a // 8 >= b:
				a = a // 8
				c = c + 1
			elif a % 4 == 0 and a // 4 >= b:
				a = a // 4
				c = c + 1
			elif a % 2 == 0 and a // 2 >= b:
				a = a // 2
				c = c + 1
			else:
				break
	else:
		while a < b:
			if a * 8 <= b:
				a = a * 8
				c = c + 1
			elif a * 4 <= b:
				a = a * 4
				c = c + 1
			elif a * 2 <= b:
				a = a * 2
				c = c + 1
			else:
				break
	if a == b:
		print(c)
	else:
		print('-1')


import sys
from math import log
from collections import *
ip = lambda : sys.stdin.readline().rstrip()
for test in range(int(ip())):
	(a, b) = map(int, ip().split())
	(a, b) = (min(a, b), max(a, b))
	if a == b:
		print(0)
		continue
	if b % a != 0 or (a == 1 and b % 2 == 1):
		print(-1)
		continue
	v = b // a
	ans = 0
	while v % 8 == 0:
		v //= 8
		ans += 1
	while v % 4 == 0:
		ans += 1
		v //= 4
	while v > 1 and v % 2 == 0:
		ans += 1
		v //= 2
	if v != 1:
		ans = -1
	print(ans)


import sys
input = lambda : sys.stdin.readline().split('\n')[0]
import math

def solve():
	t = int(input())
	while t > 0:
		t -= 1
		(a, b) = list(map(int, input().split(' ')))
		if a == b:
			print(0)
			continue
		(x, y) = (max(a, b), min(a, b))
		if x % y == 0:
			z = math.log(x // y, 2)
			if x // y == 2 ** round(z):
				z = round(z)
				print(math.ceil(z / 3))
				continue
		print(-1)
solve()


t = int(input())
for i in range(t):
	(a, b) = list(map(int, input().split()))
	if a == b:
		print(0)
	elif a % b != 0 and b % a != 0:
		print(-1)
	else:
		(a, b) = (max(a, b), min(a, b))
		ans = a // b
		a = list(bin(ans))
		a = a[2:]
		if a[0] == '1' and a[1:].count('1') == 0:
			a = a[1:]
			k = len(a)
			cost = k // 3
			k = k % 3
			cost += k // 2
			k = k % 2
			cost += k
			print(cost)
		else:
			print(-1)


from math import log
for i in range(int(input())):
	(a, b) = map(int, input().split())
	c = min(a, b)
	d = max(a, b)
	ans = 0
	while c < d:
		c *= 2
		ans += 1
	if c == d:
		print(ans // 3 + ans % 3 // 2 + ans % 3 % 2)
	else:
		print(-1)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
		continue
	elif a < b and b % a == 0:
		n = b // a
	elif b < a and a % b == 0:
		n = a // b
	else:
		print(-1)
		continue
	cnt = 0
	while n % 2 == 0:
		n //= 2
		cnt += 1
	if n > 1:
		print(-1)
		continue
	print((cnt + 2) // 3)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())

def solve(t):
	(a, b) = t
	steps = 0
	while a != b:
		if a < b:
			if a * 8 <= b:
				a *= 8
			elif a * 4 <= b:
				a *= 4
			elif a * 2 <= b:
				a *= 2
			else:
				print(-1)
				return
		elif a % 8 == 0 and a // 8 >= b:
			a //= 8
		elif a % 4 == 0 and a // 4 >= b:
			a //= 4
		elif a % 2 == 0 and a // 2 >= b:
			a //= 2
		else:
			print(-1)
			return
		steps += 1
	print(steps)
T = inp()
tests = []
for _ in range(T):
	tests.append(inlt())
for t in tests:
	solve(t)


import math
try:
	t = int(input())
	for i in range(t):
		(a, b) = list(map(int, input().split()))
		c = 0
		if a > b:
			(a, b) = (b, a)
		while a < b:
			a *= 2
			c += 1
		if a == b:
			print(math.ceil(c / 3))
		else:
			print(-1)
except:
	pass


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	if n == m:
		print('0')
	else:
		if n < m:
			(n, m) = (m, n)
		res = 0
		while n > m:
			if n // 8 >= m and n % 8 == 0:
				res += 1
				n = n // 8
			elif n // 4 >= m and n % 4 == 0:
				res += 1
				n = n // 4
			elif n // 2 >= m and n % 2 == 0:
				res += 1
				n = n // 2
			else:
				break
		if n == m:
			print(res)
		else:
			print('-1')


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	d = max(a, b)
	c = min(a, b)
	cnt = f = 0
	while c < d:
		if c * 8 <= d:
			c = c * 8
		elif c * 4 <= d:
			c = c * 4
		else:
			c = c * 2
		cnt += 1
		if c == d:
			break
		if c > d:
			f = 1
			break
	if f == 1:
		print('-1')
	else:
		print(cnt)


from sys import stdin
inp = lambda : stdin.readline().strip()
t = int(inp())
for _ in range(t):
	(a, b) = [int(x) for x in inp().split()]
	flag = True
	if a < b:
		(a, b) = (b, a)
	if a % b == 0:
		x = a // b
		ans = 0
		while True:
			if x % 8 == 0:
				x //= 8
				ans += 1
			elif x % 4 == 0:
				x //= 4
				ans += 1
			elif x % 2 == 0:
				x //= 2
				ans += 1
			elif x == 1:
				break
			else:
				flag = False
				break
	else:
		flag = False
	if flag:
		print(ans)
	else:
		print(-1)


import math
t = int(input())
while t:
	t = t - 1
	ans = 0
	(a, b) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	if a == b:
		print(0)
	elif b % 2 != 0 or b % a != 0:
		print(-1)
	else:
		while a < b:
			a = a * 2
			ans += 1
		if a != b:
			print(-1)
		else:
			eight = int(ans / 3)
			ans = ans % 3
			four = int(ans / 2)
			ans = ans % 2
			two = ans
			print(eight + four + two)


import math
for s in [*open(0)][1:]:
	(a, b) = map(int, s.split())
	d = math.gcd(a, b)
	a = f'{a // d:b}'
	b = f'{b // d:b}'
	print((-1, 0 - -abs(len(a) - len(b)) // 3)[{*a[1:]} <= {'0'} >= {*b[1:]}])
num_inp = lambda : int(input())
arr_inp = lambda : list(map(int, input().split()))
sp_inp = lambda : map(int, input().split())
str_inp = lambda : input()


from sys import stdin
from math import ceil

def func():
	return
for _ in range(int(stdin.readline())):
	(a, b) = map(int, stdin.readline().split())
	if a == b:
		print(0)
		continue
	a = bin(a)[2:]
	b = bin(b)[2:]
	cond = True
	for i in range(min(len(a), len(b))):
		if a[i] != b[i]:
			cond = False
			break
	if cond == True:
		flag = 0
		if len(a) >= len(b):
			for j in range(i + 1, max(len(a), len(b))):
				if a[j] == '1':
					flag = 1
					break
		else:
			for j in range(i + 1, max(len(a), len(b))):
				if b[j] == '1':
					flag = 1
					break
		if flag == 1:
			print(-1)
		else:
			count = j - i
			print(count // 3 + count % 3 // 2 + count % 3 % 2)
	else:
		print(-1)


t = int(input())
answer = []
for test in range(t):
	(a, b) = list(map(int, input().split(' ')))
	count = 0
	if a > b:
		(b, a) = (a, b)
	if b % a:
		answer.append(str(-1))
	else:
		x = b // a
		while x > 1:
			if not x % 8:
				count += 1
				x = x // 8
			elif not x % 4:
				count += 1
				x = x // 4
			elif not x % 2:
				count += 1
				x = x // 2
			else:
				count = -1
				break
		answer.append(str(count))
print('\n'.join(answer))


for _ in range(int(input())):
	(a, b) = [int(x) for x in input().split()]
	if a > b:
		(a, b) = (b, a)
	if a == b:
		print(0)
	elif b % a != 0 and a > 1:
		print(-1)
	elif a == 1 and b % 2 != 0:
		print(-1)
	else:
		r = b // a
		if r % 2 != 0:
			print(-1)
		else:
			d = 0
			while r > 1:
				if r % 2:
					break
				r = r // 2
				d += 1
			if r > 1:
				print(-1)
			else:
				d8 = d // 3
				d = d - d8 * 3
				if d > 0:
					d4 = d // 2
				else:
					d4 = 0
				d = d - d4 * 2
				if d > 0:
					d2 = d
				else:
					d2 = 0
				print(d8 + d4 + d2)


for _ in range(int(input())):
	(a, b) = [int(x) for x in input().split()]
	p = min(a, b)
	q = max(a, b)
	if q == p:
		print(0)
	elif q % p != 0:
		print(-1)
	else:
		ss = 0
		k = q // p
		while k % 8 == 0:
			k //= 8
			ss += 1
		while k % 4 == 0:
			k //= 4
			ss += 1
		while k % 2 == 0:
			k //= 2
			ss += 1
		if k == 1:
			print(ss)
		else:
			print(-1)


from sys import stdin, stdout
from collections import deque
input = stdin.readline

def print(x='', end='\n'):
	stdout.write(str(x) + end)

def solve():
	(a, b) = map(int, input().split())
	(a, b) = (max(a, b), min(a, b))
	if a % b != 0:
		print(-1)
		return
	a //= b
	if a & a - 1:
		print(-1)
		return
	ans = 0
	while a % 8 == 0:
		a //= 8
		ans += 1
	while a % 4 == 0:
		a //= 4
		ans += 1
	while a % 2 == 0:
		a //= 2
		ans += 1
	if a > 1:
		print(-1)
	print(ans)
tt = 1
tt = int(input())
for __ in range(tt):
	solve()


def recurr1(a, b, c):
	if a * 8 <= b:
		a *= 8
		if a == b:
			c += 1
		else:
			c += 1
			c = recurr1(a, b, c)
	elif a * 4 <= b:
		a *= 4
		if a == b:
			c += 1
		else:
			c += 1
			c = recurr1(a, b, c)
	elif a * 2 <= b:
		a *= 2
		if a == b:
			c += 1
		else:
			c += 1
			c = recurr1(a, b, c)
	else:
		c = -1
	return c
t = int(input())
for i in range(0, t):
	(a, b) = map(int, input().split())
	count = 0
	f = 0
	x = 0
	y = 0
	if a == b:
		count = 0
	elif a < b:
		x = a
		y = b
	else:
		x = b
		y = a
	if x != 0 or y != 0:
		if x == 1:
			if y % 2 == 1:
				count = -1
			else:
				c = 0
				count = recurr1(x, y, c)
		elif y % x == 0:
			c = 0
			count = recurr1(x, y, c)
		else:
			count = -1
	print(count)


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from math import sqrt, floor, factorial, gcd, log
from collections import deque, Counter, defaultdict
input = lambda : sys.stdin.readline().rstrip('\r\n')
read = lambda : list(map(int, input().strip().split(' ')))

def solve():
	for _ in range(int(input())):
		(a, b) = sorted(read())
		if a == b:
			print(0)
		elif b % a == 0 and log(b / a, 2):
			b = b // a
			c = 0
			while b % 8 == 0:
				b //= 8
				c += 1
			while b % 4 == 0:
				b //= 4
				c += 1
			while b % 2 == 0:
				b //= 2
				c += 1
			if b == 1:
				print(c)
			else:
				print(-1)
		else:
			print(-1)
solve()


from math import ceil
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	if b % a == 0:
		count = 0
		if a == b:
			print(0)
		else:
			while b > a:
				count += 1
				a *= 2
			if a > b:
				print(-1)
			if a == b:
				print(ceil(count / 3))
	else:
		print(-1)


import math

def divide(n):
	i = 0
	while n % 2 == 0 and n > 0:
		i += 1
		n //= 2
	return (n, i)
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	(an, ai) = divide(a)
	(bn, bi) = divide(b)
	if an != bn:
		print(-1)
	else:
		print(math.ceil(abs(ai - bi) / 3))


def readintlst():
	return list(map(int, input().split(' ')))

def readn():
	return int(input())
N = readn()
for _ in range(N):
	(a, b) = readintlst()
	ans = 0
	i = 0
	j = 0
	while a & 1 == 0:
		a >>= 1
		i += 1
	while b & 1 == 0:
		b >>= 1
		j += 1
	if a != b:
		print(-1)
	else:
		(dv, md) = divmod(abs(i - j), 3)
		(dv1, md1) = divmod(md, 2)
		print(dv + dv1 + md1)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if b > a:
		temp = a
		a = b
		b = temp
	counter = 0
	while a > b:
		b = b * 2
		counter += 1
	if a == b:
		print(counter // 3 + (counter % 3 != 0))
	else:
		print(-1)


cases = int(input())
compteur = 1
mm = True
for loop in range(cases):
	(nb, nbv) = map(int, input().split())
	if nb > 0 and nbv > 0:
		if nb > nbv:
			while True:
				roger = nb / nbv
				if roger == 2 or roger == 4 or roger == 8:
					break
				else:
					if nb % 8 == 0:
						nb = nb // 8
					elif nb % 4 == 0:
						nb = nb // 4
					elif nb % 2 == 0:
						nb = nb // 2
					else:
						mm = False
						compteur = -1
						break
					compteur += 1
		if nb < nbv:
			while True:
				roger = nbv / nb
				if roger == 2 or roger == 4 or roger == 8:
					break
				else:
					if nbv % 8 == 0:
						nbv = nbv // 8
					elif nbv % 4 == 0:
						nbv = nbv // 4
					elif nbv % 2 == 0:
						nbv = nbv // 2
					else:
						mm = False
						compteur = -1
						break
					compteur += 1
		if nb == nbv:
			compteur = 0
	else:
		compteur = -1
	print(compteur)
	compteur = 1
	mm = True


from __future__ import division, print_function
from sys import stdin, stdout
import bisect
import math
import heapq
i_m = 9223372036854775807

def inin():
	return int(input())

def stin():
	return input()

def spin():
	return map(int, stin().split())

def lin():
	return list(map(int, stin().split()))

def modinv(n, p):
	return pow(n, p - 2, p)

def GCD(x, y):
	x = abs(x)
	y = abs(y)
	if min(x, y) == 0:
		return max(x, y)
	while y:
		(x, y) = (y, x % y)
	return x

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l
prime = []

def SieveOfEratosthenes(n):
	global prime
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	f = []
	for p in range(2, n):
		if prime[p]:
			f.append(p)
	return f
q = []

def dfs(n, d, v, c):
	global q
	v[n] = 1
	x = d[n]
	q.append(n)
	j = c
	for i in x:
		if i not in v:
			f = dfs(i, d, v, c + 1)
			j = max(j, f)
	return j
for _ in range(inin()):
	(a, b) = spin()
	c = 0
	if a == b:
		print(0)
	elif max(a, b) % min(a, b) != 0:
		print(-1)
	else:
		q = max(a, b) // min(a, b)
		while q % 8 == 0:
			c += 1
			q = q // 8
		while q % 4 == 0:
			c += 1
			q = q // 4
		while q % 2 == 0:
			c += 1
			q = q // 2
		if q > 1:
			c = -1
		print(c)


import math
t = int(input())
for ii in range(t):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	else:
		(b, a) = (min(a, b), max(a, b))
		if a % b:
			print(-1)
		else:
			aa = int(math.log2(a // b))
			if pow(2, aa) == a // b:
				c = 0
				c += aa // 3
				aa = aa % 3
				c += aa // 2
				aa = aa % 2
				c += aa // 1
				aa = aa % 1
				print(c)
			else:
				print(-1)


def ancientComputer():
	t = int(input())
	for i in range(t):
		(a, b) = map(int, input().split())
		s = max(a, b) // min(a, b) if max(a, b) % min(a, b) == 0 else -1
		count = 0
		if s == -1:
			print(-1)
		else:
			while s > 1:
				if s % 8 == 0:
					s //= 8
				elif s % 4 == 0:
					s //= 4
				elif s % 2 == 0:
					s //= 2
				else:
					print(-1)
					break
				count += 1
			else:
				print(count)
ancientComputer()


t = int(input())
while t > 0:
	digits = [int(i) for i in input().split()]
	a = digits[0]
	b = digits[1]
	if a == b:
		print(0)
	else:
		if a < b:
			(a, b) = (b, a)
		count = 0
		while a > b:
			if b * 8 <= a and a % 8 == 0:
				count = count + 1
				b = b * 8
			elif b * 4 <= a and a % 4 == 0:
				count = count + 1
				b = b * 4
			elif b * 2 <= a and a % 2 == 0:
				count = count + 1
				b = b * 2
			else:
				break
		if a == b:
			print(count)
		else:
			print(-1)
	t = t - 1


def mult(n):
	t = 0
	while n % 2 == 0:
		t += 1
		n = n // 2
	return [t, n]
tests = int(input())
for _ in range(tests):
	(a, b) = map(int, input().split())
	[x, a1] = mult(a)
	[y, b1] = mult(b)
	if a1 == b1:
		print(abs(x - y) // 3 + abs(x - y) % 3 // 2 + abs(x - y) % 3 % 2)
	else:
		print(-1)


t = int(input())
from math import ceil
for case in range(t):
	(a, b) = map(int, input().split())
	ops = 0
	if a > b:
		(a, b) = (b, a)
	while a < b:
		ops += 1
		a *= 2
	if a == b:
		print(ceil(ops / 3))
	else:
		print(-1)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		ans = 0
	elif a < b and b % a == 0:
		k = b // a
		if k & k - 1 == 0:
			q = len(bin(k))
			p = (q - 3) // 3
			if (q - 3) % 3 == 0:
				ans = p
			else:
				ans = p + 1
		else:
			ans = -1
	elif a % b == 0:
		k = a // b
		if k & k - 1 == 0:
			q = len(bin(k))
			p = (q - 3) // 3
			if (q - 3) % 3 == 0:
				ans = p
			else:
				ans = p + 1
		else:
			ans = -1
	else:
		ans = -1
	print(ans)


for _ in range(int(input())):
	(A, B) = (int(j) for j in input().split())
	cnt = 0
	if A == B:
		print(cnt)
	elif A > B:
		if A % B != 0:
			print(-1)
		else:
			t = A // B
			flag = 0
			while t != 1:
				if t % 8 == 0:
					t = t // 8
					cnt += 1
				elif t % 4 == 0:
					t = t // 4
					cnt += 1
				elif t % 2 == 0:
					t = t // 2
					cnt += 1
				else:
					flag = 1
					break
			if flag == 0:
				print(cnt)
			else:
				print(-1)
	elif A < B:
		if B % A != 0:
			print(-1)
		else:
			t = B // A
			flag = 0
			while t != 1:
				if t % 8 == 0:
					t = t // 8
					cnt += 1
				elif t % 4 == 0:
					t = t // 4
					cnt += 1
				elif t % 2 == 0:
					t = t // 2
					cnt += 1
				else:
					flag = 1
					break
			if flag == 0:
				print(cnt)
			else:
				print(-1)


def calculate(a, b):
	count = 0
	if a % b != 0:
		return -1
	else:
		di = a // b
		while di % 8 == 0:
			di //= 8
			count += 1
		while di % 4 == 0:
			di //= 4
			count += 1
		while di % 2 == 0:
			di //= 2
			count += 1
		if di != 1:
			return -1
		else:
			return count
t = int(input())
for tt in range(t):
	(a, b) = map(int, input().split())
	if a > b:
		p = calculate(a, b)
	elif a == b:
		p = 0
	else:
		p = calculate(b, a)
	print(p)


from math import *
for i in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
		continue
	(powA, powB) = (0, 0)
	while a % 2 == 0:
		powA += 1
		a = a // 2
	while b % 2 == 0:
		powB += 1
		b = b // 2
	if a != b:
		print(-1)
	else:
		print(ceil(abs(powA - powB) / 3))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	(a, b) = (max(a, b), min(a, b))
	lst = [2, 4, 8]
	if a == b:
		print(0)
	else:

		def fun(a):
			global cnt
			lx = []
			cnt += 1
			for i in lst:
				if a % i == 0:
					lx.append(a // i)
			if len(lx) == 0:
				print(-1)
				return
			if b in lx:
				print(cnt)
				return
			else:
				fun(min(lx))
		cnt = 0
		fun(a)


from math import ceil, log2
t = int(input())

def get_r(x):
	while x % 2 == 0:
		x //= 2
	return x

def f(a, b):
	ans = -1
	if b > a:
		(a, b) = (b, a)
	(ra, rb) = (get_r(a), get_r(b))
	if ra == rb:
		ans = ceil(log2(a // b) / 3)
	return ans
answers = []
for _ in range(t):
	(a, b) = [int(i) for i in input().split()]
	ans = f(a, b)
	answers.append(ans)
for i in answers:
	print(i)


import math
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	c = 0
	while a < b:
		a = a * 8
		c += 1
	if a == b or a // 4 == b or a // 2 == b:
		print(c)
	else:
		print('-1')


import collections

def read():
	return input().strip()

def readInt():
	return int(input().strip())

def readList():
	return list(map(int, input().strip().split()))

def solve(a, b):
	[a, b] = sorted([a, b])
	ans = 0
	while a < b:
		if a * 8 <= b:
			a *= 8
		elif a * 4 <= b:
			a *= 4
		else:
			a *= 2
		ans += 1
	return ans if a == b else -1
t = readInt()
for i in range(t):
	[a, b] = readList()
	print(solve(a, b))


import math
d = {}
for i in range(61):
	d[2 ** i] = i
for i in range(int(input())):
	(a, b) = list(map(int, input().split()))
	if a == b:
		print('0')
	elif a > b:
		num = a // b
		if num in d and a % b == 0:
			ans = d[num] // 3
			if d[num] % 3 != 0:
				ans += 1
			print(int(ans))
		else:
			print('-1')
	else:
		num = b // a
		if num in d and b % a == 0:
			ans = d[num] // 3
			if d[num] % 3 != 0:
				ans += 1
			print(int(ans))
		else:
			print('-1')


test_cases = int(input())
for z in range(test_cases):
	(a, b) = list(map(int, input().split()))
	count = 0
	c = 0
	if b > a:
		d = b
		b = a
		a = d
	if a > b:
		if a % b == 0:
			x = a // b
			y = x
			while x % 2 == 0:
				x = x // 2
			if x == 1:
				while y % 8 == 0:
					count += 1
					y = y // 8
				while y % 4 == 0:
					count += 1
					y = y // 4
				while y % 2 == 0:
					count += 1
					y = y // 2
			else:
				print(-1)
				c = 1
		else:
			print(-1)
			c = 1
	if c == 0:
		print(count)


def f(q):
	cnt = 0
	while q % 2 == 0:
		cnt += 1
		q //= 2
	if q > 1:
		return -1
	res = 0
	res += cnt // 3
	cnt %= 3
	res += cnt // 2
	cnt %= 2
	res += cnt
	return res

def solve():
	(a, b) = map(int, input().split())
	(a, b) = (max(a, b), min(a, b))
	if a % b != 0:
		print(-1)
		return
	q = a // b
	print(f(q))
for cnt in range(int(input())):
	solve()


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	ans = 0
	if a == b:
		print(0)
		continue
	if a < b:
		(a, b) = (b, a)
	while a % 8 == 0 and a // 8 >= b:
		a //= 8
		ans += 1
	while a % 4 == 0 and a // 4 >= b:
		a //= 4
		ans += 1
	while a % 2 == 0 and a // 2 >= b:
		a //= 2
		ans += 1
	if a != b:
		ans = -1
	print(ans)


from collections import defaultdict as dd

def lcm(a, b):
	return a * b // gcd(a, b)

def inin():
	return int(input())

def inar():
	return list(map(int, input().split()))

def ar(element, size):
	return [element for i in range(size)]

def digitsum(num):
	su = 0
	while num:
		su += num % 10
		num //= 10
	return su

def yes():
	print('YES')

def no():
	print('NO')
Testcase = inin()
for _ in range(Testcase):
	ab = inar()
	(a, b) = (min(ab), max(ab))
	if a == b:
		print(0)
	else:
		cnt = 0
		visb = False
		while a <= b:
			if a * 8 <= b:
				a *= 8
				cnt += 1
				if a == b:
					visb = True
			elif a * 4 <= b:
				a *= 4
				cnt += 1
				if a == b:
					visb = True
			elif a * 2 <= b:
				a *= 2
				cnt += 1
				if a == b:
					visb = True
			else:
				break
		if visb:
			print(cnt)
		else:
			print(-1)


def comp(a, b):
	count = 0
	q = a // b
	if a % b == 0 and a % 2 == 0 and (q % 2 == 0):
		binary = bin(q)[2:]
		zeros = binary.count('0')
		ones = binary.count('1')
		if ones == 1:
			eights = zeros // 3
			zeros = zeros % 3
			fours = zeros // 2
			zeros = zeros % 2
			two = zeros
			count = eights + fours + two
		else:
			count = -1
	else:
		count = -1
	print(count)
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	elif a > b:
		comp(a, b)
	else:
		comp(b, a)


t = int(input())
for k in range(t):
	(a, b) = map(int, input().split())
	x = 0
	y = 0
	if a > b:
		mi = b
		ma = a
	elif a < b:
		mi = a
		ma = b
	if a == b:
		print(0)
		continue
	else:
		while ma % 2 != 1:
			x += 1
			ma = ma // 2
		while mi % 2 != 1:
			y += 1
			mi = mi // 2
		if ma != mi:
			print(-1)
		else:
			ans = abs(x - y)
			ans1 = 0
			ans1 = ans1 + ans // 3
			ans = ans % 3
			ans1 = ans1 + ans // 2
			ans = ans % 2
			if ans == 1:
				ans1 = ans1 + 1
			print(ans1)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	z = 0
	if a == b:
		print(0)
	elif a > b:
		while a % 2 == 0 and a // 2 >= b:
			z += 1
			a = a // 2
		if z == 0 or a != b:
			print(-1)
		elif z % 3 == 0:
			print(z // 3)
		else:
			print(z // 3 + 1)
	else:
		while a * 2 <= b:
			z += 1
			a = a * 2
		if z == 0 or a != b:
			print(-1)
		elif z % 3 == 0:
			print(z // 3)
		else:
			print(z // 3 + 1)


from math import log2
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if b <= a:
		(a, b) = (b, a)
	if b % a != 0 or b // a != 2 ** int(log2(b // a)):
		print(-1)
		continue
	cnt = 0
	p = int(log2(b // a))
	cnt += p // 3
	p %= 3
	cnt += p // 2
	p %= 2
	cnt += p
	print(cnt)


t = int(input())
for ii in range(t):
	(a, b) = map(int, input().split())
	if max(a, b) % min(a, b) != 0:
		print(-1)
	else:
		d = max(a, b) // min(a, b)
		cnt = 0
		while d > 1 and d % 2 == 0:
			cnt += 1
			d //= 2
		if d > 1:
			print(-1)
		else:
			print(cnt // 3 + (1 if cnt % 3 != 0 else 0))


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	if b % a:
		print(-1)
	else:
		k = b // a
		count = 0
		while k > 1:
			if k % 2 == 0:
				k = k // 2
				count += 1
			else:
				print(-1)
				break
		if k == 1:
			ans = count // 3
			ans += count % 3 // 2
			ans += count % 3 % 2
			print(ans)


from math import log2, pow
t = int(input())
while t > 0:
	t -= 1
	l = [int(x) for x in input().split()]
	a = l[0]
	b = l[1]
	if a < b and b % a > 0 or (a > b and a % b > 0):
		print(-1)
	else:
		v1 = a < b and b // a or (a > b and a // b) or 1
		val = log2(v1)
		if val.is_integer() == False or pow(2, val) != v1:
			print(-1)
		else:
			tot = val // 3
			val %= 3
			tot += val // 2
			val %= 2
			tot += val
			print(int(tot))


from collections import deque
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
		continue
	if a > b:
		(a, b) = (b, a)
	ans = 0
	while b % 8 == 0 and b // 8 >= a:
		b = b // 8
		ans += 1
	while b % 4 == 0 and b // 4 >= a:
		b = b // 4
		ans += 1
	while b % 2 == 0 and b // 2 >= a:
		b = b // 2
		ans += 1
	while a < b and a * 8 <= b:
		a = a * 8
		ans += 1
	while a < b and a * 4 <= b:
		a = a * 4
		ans += 1
	while a < b and a * 2 <= b:
		a = a * 2
		ans += 1
	if a == b:
		print(ans)
		continue
	ch = False
	if a // 2 == b:
		ans += 1
		ch = True
	elif a // 4 == b:
		ans += 1
		ch = True
	elif a // 8 == b:
		ans += 1
		ch = True
	elif a * 2 == b:
		ans += 1
		ch = True
	elif a * 4 == b:
		ans += 1
		ch = True
	elif a * 8 == b:
		ans += 1
		ch = True
	if ans == 0 or ch == False:
		print(-1)
	else:
		print(ans)


import math
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	c = max(x, y)
	d = min(x, y)
	m = 0
	while c > d:
		d = d * 2
		m = m + 1
	if c == d:
		n = m // 3
		m = m % 3
		n = n + m // 2
		m = m % 2
		n = n + m
		print(n)
	else:
		print(-1)


n = int(input())
for _ in range(n):
	xy = input()
	x = int(xy.split()[0])
	y = int(xy.split()[1])
	if x == y:
		print(0)
	else:
		if y > x:
			(x, y) = (y, x)
		if x % y != 0:
			print(-1)
		else:
			counter = 0
			z = x // y
			while z % 8 == 0:
				counter = counter + 1
				z = z // 8
			while z % 4 == 0:
				counter = counter + 1
				z = z // 4
			while z % 2 == 0:
				counter = counter + 1
				z = z // 2
			if z != 1:
				print(-1)
			else:
				print(counter)


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	a = min(x, y)
	b = max(x, y)
	count = lol = 0
	if a == b:
		print(0)
	else:
		while a <= b:
			if b % 8 == 0 and b // 8 >= a:
				b = b // 8
				count += 1
				lol = 8
			elif b % 4 == 0 and b // 4 >= a:
				b = b // 4
				count += 1
				lol = 4
			elif b % 2 == 0 and b // 2 >= a:
				b = b // 2
				count += 1
				lol = 2
			else:
				break
		if a != b:
			print(-1)
		else:
			print(count)


def get(n):
	while n % 2 == 0:
		n = n // 2
	return n
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
		continue
	count = 0
	f = 0
	if a > b:
		(a, b) = (b, a)
	t = get(a)
	if get(b) != t:
		print(-1)
		continue
	b = b // a
	while b % 8 == 0:
		count += 1
		b = b // 8
	if b > 1:
		count += 1
	print(count)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = 0
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans

def sieve_of_eratosthenes(n):
	ans = []
	arr = [1] * (n + 1)
	(arr[0], arr[1], i) = (0, 0, 2)
	while i * i <= n:
		if arr[i] == 1:
			j = i + i
			while j <= n:
				arr[j] = 0
				j += i
		i += 1
	for k in range(n):
		if arr[k] == 1:
			ans.append(k)
	return ans

def nc2(x):
	if x == 1:
		return 0
	else:
		return x * (x - 1) // 2
from math import *
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	(ab, bb) = (bin(a), bin(b))
	ab = ab[2:]
	bb = bb[2:]
	flag = 1
	for i in range(len(ab)):
		if ab[i] != bb[i]:
			flag = 0
			break
	for i in range(len(ab), len(bb)):
		if bb[i] != '0':
			flag = 0
			break
	if flag == 0:
		print(-1)
	else:
		tot = len(bb) - len(ab)
		ans = tot // 3
		tot %= 3
		ans += tot // 2
		tot %= 2
		ans += tot
		print(ans)


import math
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	e = 0
	if a > b:
		(a, b) = (b, a)
	for i in range(100):
		if a < b:
			a *= 2
			e += 1
		elif a == b:
			break
		else:
			e = -1
	if e == -1:
		print(-1)
	else:
		print(e // 3 + int(e % 3 != 0))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a % 2 != 0 and b < a:
		print(-1)
	elif a > b and a // b % 2 != 0:
		print(-1)
	elif a < b and b // a % 2 != 0:
		print(-1)
	elif b == a:
		print(0)
	elif b % a != 0 and a % b != 0:
		print(-1)
	else:
		if b < a:
			d = a // b
		elif a < b:
			d = b // a
		ct = 0
		l = [2, 4, 8]
		i = 2
		while d != 0 and i >= 0:
			while d % l[i] == 0 and d > 0:
				d = d // l[i]
				ct += 1
				if d < l[i]:
					d = d % l[i]
					break
			i -= 1
		if d != 1:
			print(-1)
		else:
			print(ct)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	(mx, mn) = (max(a, b), min(a, b))
	ctr = 0
	a = mx / mn
	if mx % mn == 0:
		a = mx // mn
	else:
		ctr = 2
	if ctr == 0:
		for j in range(62):
			if a >> j & 1:
				ctr += 1
	if ctr == 1:
		ctr2 = 0
		while a > 1:
			a /= 8
			ctr2 += 1
		print(ctr2)
	else:
		print(-1)


from sys import stdin
input = stdin.readline

def p1(a, b):
	if a % b:
		return -1
	div = a // b
	if div % 2:
		return -1
	c = 0
	while not div % 8:
		div //= 8
		c += 1
	while not div % 4:
		div //= 4
		c += 1
	while not div % 2:
		div //= 2
		c += 1
	return c if div == 1 else -1
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	else:
		print(p1(max(a, b), min(a, b)))


def floyd(n):
	while n % 2 == 0:
		n = n // 2
	return n
n = int(input())
for i in range(n):
	ans = 0
	(a, b) = map(int, input().split())
	g = floyd(a)
	if g != floyd(b):
		ans = -1
	else:
		if a < b:
			(a, b) = (b, a)
		a = a // b
		while a >= 8:
			a = a // 8
			ans += 1
		if a > 1:
			ans += 1
	print(ans)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	cnt = 0
	while a < b:
		a *= 2
		cnt += 1
	if a > b:
		print(-1)
		continue
	res = cnt // 3
	res += cnt % 3 // 2
	res += cnt % 3 % 2
	print(res)


import math

def isPowerOfTwo(n):
	if n == 0:
		return False
	while n != 1:
		if n % 2 != 0:
			return False
		n = n // 2
	return True

def find_power(n):
	count = 0
	while n > 1:
		count += 1
		n = n // 2
	return count
for i in range(int(input())):
	(a, b) = map(int, input().split())
	x = max(a, b)
	y = min(a, b)
	if x % y == 0:
		z = x // y
		if isPowerOfTwo(z):
			power = find_power(z)
			ans = 0
			while power > 0:
				if power > 2:
					ans += 1
					power -= 3
				elif power > 1:
					ans += 1
					power -= 2
				else:
					ans += 1
					power -= 1
			print(ans)
		else:
			print(-1)
	else:
		print(-1)


t = int(input())
for z in range(t):
	(a, b) = map(int, input().split())
	count = 0
	x = 0
	if a == 0 or b == 0:
		print(-1)
		break
	if a >= b:
		flag = 1
		if a % b == 0:
			c = a // b
			while c > 1:
				if c % 2 != 0:
					flag = 0
				c = c // 2
			if flag == 1:
				while a != b:
					b = b * 2
					count += 1
				x += count // 3
				count = count % 3
				x += count // 2
				count = count % 2
				x += count
				print(x)
			else:
				print(-1)
		else:
			print(-1)
	else:
		flag = 1
		if b % a == 0:
			c = b // a
			while c > 1:
				if c % 2 != 0:
					flag = 0
				c = c // 2
			if flag == 1:
				while b != a:
					a = a * 2
					count += 1
				x += count // 3
				count = count % 3
				x += count // 2
				count = count % 2
				x += count
				print(x)
			else:
				print(-1)
		else:
			print(-1)


import sys, math
pows = []
for i in range(60):
	pows.append(2 ** i)
max_int = 1000000001
min_int = -max_int
t = int(input())
for _t in range(t):
	(a, b) = map(int, sys.stdin.readline().split())
	if a > b:
		(a, b) = (b, a)
	for (num, elem) in enumerate(pows):
		if a * elem == b:
			print(math.ceil(num / 3))
			break
	else:
		print(-1)


import math
import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
		continue
	if a > b:
		(a, b) = (b, a)
	if b % a:
		print(-1)
	else:
		x = b // a
		k = 0
		while x > 1:
			if x % 2:
				k = 0
				break
			x //= 2
			k += 1
		if k == 0:
			print(-1)
		else:
			print(math.ceil(k / 3))


t = int(input())
while t != 0:
	oper1 = 0
	oper2 = 0
	oper3 = 0
	test = 1
	c = 0
	(a, b) = map(int, input().split())
	if a != b:
		if a > b:
			gg = a // b
			m = a % b
		else:
			gg = b // a
			m = b % a
		s = int(gg)
		if m != 0 or (a % 2 != 0 and b % 2 != 0):
			print(-1)
		else:
			while s >= 8:
				s = s >> 3
				oper1 += 1
			if oper1 > 0:
				test = 8 ** oper1
			while s >= 4:
				s = s >> 2
				oper2 += 1
			if oper2 > 0:
				test = test * 4 ** oper2
			while s >= 2:
				s = s >> 1
				oper3 += 1
			if oper3 > 0:
				test = test * 2 ** oper3
			if gg + m - test != 0:
				print(-1)
			else:
				print(oper1 + oper2 + oper3)
	else:
		print(0)
	t = t - 1


def swap(a, b):
	if a < b:
		return (a, b)
	return (b, a)

def solve(a, b):
	(a, b) = swap(a, b)
	ans = 0
	while b > a:
		if b % 8 == 0:
			ans += 1
			b = b // 8
		elif b % 4 == 0:
			ans += 1
			b = b // 4
		elif b % 2 == 0:
			ans += 1
			b = b // 2
		else:
			break
	if a == b:
		return ans
	elif b * 4 == a:
		return ans
	elif b * 2 == a:
		return ans
	else:
		return -1

def read():
	t = int(input())
	for i in range(t):
		(a, b) = list(map(int, input().strip().split()))
		ans = solve(a, b)
		print(ans)
read()


import math
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	bin_a = bin(a)[2:]
	bin_b = bin(b)[2:]
	newa = a << len(bin_b) - len(bin_a)
	if newa != b:
		print(-1)
		continue
	else:
		lstb = math.log2(b & -b)
		lsta = math.log2(a & -a)
		diff = lstb - lsta
		case = [3, 2, 1]
		i = 0
		ans = 0
		while diff > 0:
			if diff >= case[i]:
				diff -= case[i]
				ans += 1
			else:
				i += 1
		print(ans)


from collections import Counter
import math
import sys
from bisect import bisect, bisect_left, bisect_right

def input():
	return sys.stdin.readline().strip()

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def mod():
	return 10 ** 9 + 7
for _ in range(INT()):
	(a, b) = MAP()
	if a == b:
		print(0)
	else:
		if a < b:
			(a, b) = (b, a)
		ans = 0
		while a > b:
			if a // 8 >= b and a % 8 == 0:
				ans += 1
				a = a // 8
			elif a // 4 >= b and a % 4 == 0:
				ans += 1
				a = a // 4
			elif a // 2 >= b and a % 2 == 0:
				ans += 1
				a = a // 2
			else:
				break
		if a == b:
			print(ans)
		else:
			print(-1)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		ans = 0
	else:
		l = [8, 4, 2]
		(a, b) = (max(a, b), min(a, b))
		if a % b == 0:
			total = a // b
			count = 0
			for i in l:
				while total % i == 0 and total > 1:
					total = total // i
					count += 1
					if total == 1:
						break
			if total == 1:
				ans = count
			else:
				ans = -1
		else:
			ans = -1
	print(ans)


import sys
input = sys.stdin.readline

def getInt():
	return int(input())

def getVars():
	return map(int, input().split())

def getList():
	return list(map(int, input().split()))

def getStr():
	return input().strip()
t = getInt()
for _ in range(t):
	(a, b) = getVars()
	if a == b:
		print(0)
		continue
	a2 = bin(a)
	b2 = bin(b)
	if len(a2) < len(b2):
		(a2, b2) = (b2, a2)
	if a2[:len(b2)] == b2 and a2[len(b2):] == '0' * (len(a2) - len(b2)):
		res = len(a2) - len(b2)
		if res % 3 == 0:
			print(res // 3)
		else:
			print(res // 3 + 1)
	else:
		print(-1)


import math
for asdf in range(int(input())):
	nums = list(input().split())
	a = int(nums[0])
	b = int(nums[1])
	if a > b:
		t = a
		a = b
		b = t
	div = int(b % a)
	if div != 0:
		print(-1)
	else:
		c = False
		for i in range(61):
			if int(pow(2, i)) == b // a:
				c = True
		if not c:
			print(-1)
		else:
			cur = math.log(b // a) / math.log(2)
			cnt = 0
			e = int(cur / 3)
			cnt += e
			cur = cur - e * 3
			f = int(cur / 2)
			cnt += f
			cur = cur - f * 2
			cnt += cur
			print(int(cnt))


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	c = 0
	large = max(a, b)
	small = min(a, b)
	while small < large:
		if large % 2 == 0:
			large = large // 2
			c += 1
		else:
			break
	if large == small:
		if c % 3 == 0:
			print(c // 3)
		else:
			print(c // 3 + 1)
	else:
		print(-1)


import math
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a % 2 != 0 and b % 2 != 0 and (a != b):
		print(-1)
		continue
	if a == b:
		print(0)
		continue
	elif a < b:
		ans = 0
		while True:
			if a * 8 <= b:
				a *= 8
				ans += 1
			else:
				break
		while True:
			if a * 4 <= b:
				a *= 4
				ans += 1
			else:
				break
		while True:
			if a * 2 <= b:
				a *= 2
				ans += 1
			else:
				break
		if a == b:
			print(ans)
		else:
			print(-1)
	else:
		(a, b) = (b, a)
		ans = 0
		while True:
			if a * 8 <= b:
				a *= 8
				ans += 1
			else:
				break
		while True:
			if a * 4 <= b:
				a *= 4
				ans += 1
			else:
				break
		while True:
			if a * 2 <= b:
				a *= 2
				ans += 1
			else:
				break
		if a == b:
			print(ans)
		else:
			print(-1)


for i in range(int(input())):
	(a, b) = sorted(list(map(int, input().split())))
	c = 0
	if a == b:
		print(0)
	elif b % a == 0:
		while b != a and b % 2 == 0:
			b = b // 2
			c += 1
		if c > 3 and a == b:
			if c % 3 == 0:
				print(c // 3)
			else:
				print(c // 3 + 1)
		elif c > 0 and a == b:
			print(1)
		else:
			print(-1)
	else:
		print(-1)


def solve(a, b):
	if a < b:
		(a, b) = (b, a)
	ans = 0
	while a % 8 == 0 and a // 8 >= b:
		ans += 1
		a //= 8
	while a % 4 == 0 and a // 4 >= b:
		ans += 1
		a //= 4
	while a % 2 == 0 and a // 2 >= b:
		a //= 2
		ans += 1
	if b == a:
		return ans
	else:
		return -1
t = int(input())
for i in range(t):
	(a, b) = list(map(int, input().split()))
	print(solve(a, b))


t = int(input())

def log2(c):
	ans = 0
	base = 1
	while c > base:
		base += base
		ans += 1
	if c == 2 ** ans:
		return ans
	else:
		return -1
import math
for boomer in range(t):
	(a, b) = [int(i) for i in input().split()]
	if a == b:
		print(0)
	else:
		if a > b:
			(a, b) = (b, a)
		if b % a != 0:
			print(-1)
		else:
			d = log2(b // a)
			if d != -1:
				ans = 0
				ans += d // 3
				d %= 3
				ans += d // 2 + d % 2
				print(ans)
			else:
				print(-1)


import sys, re, math
from decimal import *
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd, log2, floor
from heapq import heappush, heappop, heapify, nlargest, nsmallest

def STR():
	return list(input())

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST():
	return list(map(int, input().split()))

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def sortListWithIndex(listOfTuples, idx):
	return sorted(listOfTuples, key=lambda x: x[idx])

def sortDictWithVal(passedDic):
	temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))[::-1]
	toret = {}
	for tup in temp:
		toret[tup[0]] = tup[1]
	return toret

def sortDictWithKey(passedDic):
	return dict(OrderedDict(sorted(passedDic.items())))
INF = float('inf')
mod = 10 ** 9 + 7
t = INT()
while t != 0:
	(a, b) = MAP()
	if a == b:
		print(0)
	else:
		if a > b:
			abc = a
			a = b
			b = abc
		flag = 0
		for i in range(61):
			if a << i == b:
				flag = 1
				break
		if flag == 1:
			ans = 0
			if i >= 3:
				ans = i // 3
				i = i % 3
			if i >= 2:
				ans += i // 2
				i %= 2
			if i == 1:
				ans += 1
			print(ans)
		else:
			print(-1)
	t -= 1


import sys
import math

def I():
	return int(sys.stdin.readline())

def IL():
	return list(map(int, sys.stdin.readline().strip().split()))

def ILS():
	return list(map(str, sys.stdin.readline().strip().split()))
t = I()
for iii in range(t):
	(a, b) = IL()
	if a == b:
		print(0)
		continue
	if a > b:
		(a, b) = (b, a)
	n = a
	cnt = 0
	while n < b:
		n = n * 2
		cnt += 1
	if n == b:
		ans = 0
		ans += cnt // 3
		cnt = cnt % 3
		ans += cnt // 2
		cnt = cnt % 2
		ans += cnt
		print(ans)
	else:
		print(-1)


import sys
import math
import collections
from sys import stdin, stdout, setrecursionlimit
import bisect as bs
setrecursionlimit(2 ** 20)
M = 10 ** 9 + 7
p = 1
d = {}
c = 0
while p < 10 ** 18:
	d[p] = c
	p *= 2
	c += 1
T = int(stdin.readline())
for _ in range(T):
	(a, b) = list(map(int, stdin.readline().split()))
	if a % b != 0 and b % a != 0:
		print(-1)
		continue
	if a % b == 0:
		q = a // b
		if q not in d:
			print(-1)
			continue
		q = d[q]
		print(q // 3 + (1 if q % 3 != 0 else 0))
		continue
	if b % a == 0:
		q = b // a
		if q not in d:
			print(-1)
			continue
		q = d[q]
		print(q // 3 + (1 if q % 3 != 0 else 0))


def main():
	for _ in range(int(input())):
		(a, b) = map(int, input().split())
		if a > b:
			(a, b) = (b, a)
		if b % a:
			print(-1)
			continue
		c = b // a
		d = 0
		while ~c & 1:
			c >>= 1
			d += 1
		if 1 < c:
			print(-1)
			continue
		print((d + 2) // 3)
main()


for _ in range(0, int(input())):
	(a, b) = map(int, input().split())
	counter = 0
	if a == b:
		print(0)
		continue
	while True:
		if a % 2 == 0:
			counter += 1
			a = a // 2
		else:
			break
	counter1 = 0
	while True:
		if b % 2 == 0:
			counter1 += 1
			b = b // 2
		else:
			break
	if a != b:
		print(-1)
	else:
		diff = abs(counter - counter1)
		ans = diff // 3
		if diff % 3 != 0:
			ans += 1
		print(ans)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	(a, b) = (max(a, b), min(a, b))
	if a % b != 0:
		print(-1)
		continue
	ct = 0
	f = True
	while a != b:
		if a % 8 == 0 and a // 8 >= b:
			a //= 8
			ct += 1
			continue
		elif a % 4 == 0 and a // 4 >= b:
			a //= 4
			ct += 1
			continue
		elif a % 2 == 0 and a // 2 >= b:
			a //= 2
			ct += 1
			continue
		else:
			f = False
			break
	if f:
		print(ct)
	else:
		print(-1)


t = int(input())

def decbinary(num):
	if num < 2:
		return str(num)
	else:
		num1 = num % 2
		return decbinary(num // 2) + str(num1)
for _ in range(t):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	elif a > b:
		s1 = decbinary(a)
		s2 = decbinary(b)
		l2 = len(s2)
		l1 = len(s1)
		s3 = '0' * (l1 - l2)
		if s1[:l2] == s2 and s1[l2:] == s3:
			num = l1 - l2
			ct = 0
			ct += num // 3
			ct += num % 3 // 2
			ct += num % 3 % 2
			print(ct)
		else:
			print(-1)
	else:
		s1 = decbinary(a)
		s2 = decbinary(b)
		l2 = len(s2)
		l1 = len(s1)
		s3 = '0' * (l2 - l1)
		if s2[:l1] == s1 and s2[l1:] == s3:
			num = l2 - l1
			ct = 0
			ct += num // 3
			ct += num % 3 // 2
			ct += num % 3 % 2
			print(ct)
		else:
			print(-1)


def min_op(a, b):
	if a == b:
		return 0
	n1 = max(a, b)
	n2 = min(a, b)
	count = 0
	if n1 % n2:
		return -1
	else:
		while n1 > n2:
			if n1 % 8 == 0 and (n1 // 8 % 2 == 0 and n1 // 8 >= n2 or (n1 // 8 % 2 and n1 // 8 == n2)):
				n1 //= 8
				count += 1
				continue
			elif n1 % 4 == 0 and (n1 // 4 % 2 == 0 and n1 // 4 >= n2 or (n1 // 4 % 2 and n1 // 4 == n2)):
				n1 //= 4
				count += 1
				continue
			elif n1 % 2 == 0 and (n1 // 2 % 2 == 0 and n1 // 2 >= n2 or (n1 // 2 % 2 and n1 // 2 == n2)):
				n1 //= 2
				count += 1
				continue
			else:
				return -1
	return count
t = int(input())
for _ in range(t):
	ab = input().split()
	a = int(ab[0])
	b = int(ab[1])
	print(min_op(a, b))


import math
t = int(input())
for you in range(t):
	l = input().split()
	a = int(l[0])
	b = int(l[1])
	if a > b:
		(a, b) = (b, a)
	if b % a != 0:
		print(-1)
	else:
		z = b // a
		if z & z - 1:
			print(-1)
		else:
			pow = 0
			while z > 0:
				z = z // 2
				pow += 1
			pow = pow - 1
			print(math.ceil(pow / 3))


import math
from decimal import Decimal
t = int(input())
for test in range(t):
	(a, b) = map(Decimal, input().split())
	c = max(a, b) / min(a, b)
	power = 0
	fl = 0
	while c != 1:
		if c % 2 != 0:
			fl = 1
			break
		power += 1
		c = c / 2
	if fl == 1:
		print(-1)
	else:
		print(math.ceil(power / 3))


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	if b % a == 0 and a != b:
		d = b // a
		flag = False
		c = 0
		while d > 1 and (not flag):
			if d % 2 == 1:
				flag = True
			d = d // 2
			c += 1
		if not flag:
			if c >= 3 and c % 3 == 0:
				print(c // 3)
			elif c > 3 and c % 3 != 0:
				print(c // 3 + 1)
			else:
				print(1)
		else:
			print(-1)
	elif a == b:
		print(0)
	else:
		print(-1)


import math
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	v1 = min(a, b)
	v2 = max(a, b)
	if v1 == v2:
		print(0)
		continue
	if v2 % v1 != 0 or (v1 != v2 and v2 & 1 == 1):
		print(-1)
		continue
	var2 = math.floor(math.log2(v2))
	var1 = math.floor(math.log2(v1))
	ans = var2 - var1
	ans = math.ceil(ans / 3)
	for i in range(0, ans - 1):
		v1 = v1 << 3
	arr = [v1 << 1, v1 << 2, v1 << 3]
	if v2 in arr:
		print(ans)
	else:
		print(-1)


def log(m):
	ans = 0
	while m:
		m = m // 2
		ans += 1
	return ans - 1
t = int(input())
for _ in range(t):
	(w, c) = map(int, input().split())
	if w >= c:
		if w % c == 0:
			x = w // c
			if x & x - 1 == 0:
				c = log(x)
				ans = c // 3
				if c % 3:
					ans += 1
				print(ans)
			else:
				print(-1)
		else:
			print(-1)
	elif c % w == 0:
		x = c // w
		if x & x - 1 == 0:
			c = log(x)
			ans = c // 3
			if c % 3:
				ans += 1
			print(ans)
		else:
			print(-1)
	else:
		print(-1)


t = int(input())
while t:
	t -= 1
	(a, b) = map(int, input().split())
	if a % b and b % a:
		print(-1)
	else:
		if a > b:
			x = a // b
		else:
			x = b // a
		c = 0
		while x % 8 == 0:
			x = x // 8
			c += 1
		while x % 4 == 0:
			x = x // 4
			c += 1
		while x % 2 == 0:
			x = x // 2
			c += 1
		if x == 1:
			print(c)
		else:
			print('-1')


import math
t = int(input())
for i in range(t):
	(x, y) = [int(x) for x in input().split()]
	ct = 0
	if x < y:
		while x < y:
			x *= 2
			ct += 1
		if x == y:
			print(math.ceil(ct / 3))
		else:
			print(-1)
	elif y < x:
		while y < x:
			y *= 2
			ct += 1
		if x == y:
			print(math.ceil(ct / 3))
		else:
			print(-1)
	else:
		print(0)


test = int(input())
for _ in range(test):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	elif a < b and b % a == 0:
		div = b // a
		op = 0
		flag = True
		while div > 1:
			if div % 8 == 0:
				op += 1
				div = div // 8
			elif div % 4 == 0:
				op += 1
				div = div // 4
			elif div % 2 == 0:
				op += 1
				div = div // 2
			else:
				print(-1)
				flag = False
				break
		if flag:
			if div == 1:
				print(op)
			else:
				print(-1)
	elif a > b and a % b == 0:
		(a, b) = (b, a)
		div = b // a
		flag = True
		op = 0
		while div > 1:
			if div % 8 == 0:
				op += 1
				div = div // 8
			elif div % 4 == 0:
				op += 1
				div = div // 4
			elif div % 2 == 0:
				op += 1
				div = div // 2
			else:
				print(-1)
				flag = False
				break
		if flag:
			if div == 1:
				print(op)
			else:
				print(-1)
	else:
		print(-1)


t = int(input())
AB = [list(map(int, input().split())) for _ in range(t)]
for i in range(t):
	ans = 0
	(a, b) = (AB[i][0], AB[i][1])
	if b > a:
		(a, b) = (b, a)
	a = format(a, 'b')
	b = format(b, 'b')
	if a == b:
		print(0)
	elif a[:len(b)] != b or a.count('1', len(b), len(a)) > 0:
		print(-1)
	else:
		a = len(a)
		b = len(b)
		tmp = a - b
		if tmp >= 3:
			ans += tmp // 3
			tmp %= 3
		if tmp >= 2:
			ans += tmp // 2
			tmp %= 2
		if tmp >= 1:
			ans += tmp
		print(ans)


import math as m
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	div = 0
	if a < b:
		(a, b) = (b, a)
	cnt = 0
	while a > b:
		b = b * 2
		cnt += 1
	if a == b:
		ans = 0
		if cnt % 3 != 0:
			ans = 1
		ans = cnt // 3 + ans
		print(ans)
	else:
		print('-1')


n = int(input())
while n > 0:
	n = n - 1
	(x, y) = map(int, input().split())
	if x > y:
		(x, y) = (y, x)
	cnt = 0
	while x < y:
		x = x * 2
		cnt = cnt + 1
	if x != y:
		print('-1')
	else:
		ans = cnt / 3 + min(cnt % 3, 1)
		print(int(ans))


import sys
import math
import collections

def set_debug(debug_mode=False):
	if debug_mode:
		fin = open('input.txt', 'r')
		sys.stdin = fin

def int_split_input():
	return list(map(int, input().split()))
t = int(input())
for ti in range(1, t + 1):
	(a, b) = list(map(int, input().split()))
	if a == b:
		print('0')
		continue
	else:
		if a < b:
			(a, b) = (b, a)
		if a % b != 0:
			print(-1)
			continue
		elif bin(a // b)[2:].count('1') != 1:
			print(-1)
			continue
		else:
			cur = 0
			while a > b:
				a = a // 8
				cur += 1
			print(cur)


from sys import stdin, stdout
import math, queue, heapq
fastinput = stdin.readline
fastout = stdout.write
t = int(fastinput())
while t:
	t -= 1
	(n, m) = map(int, fastinput().split())
	(n, m) = (min(n, m), max(n, m))
	x = 0
	if n == m:
		print(0)
	else:
		while n < m:
			n = n << 1
			x += 1
		if n != m:
			print(-1)
		else:
			s = x // 3
			x %= 3
			y = x // 2
			x %= 2
			print(s + y + x)


a = int(input())
for i in range(0, a):
	(a, b) = map(int, input().split())
	count = 0
	if a > b:
		while a > b:
			if a % 2 == 0:
				a = a // 2
				count = count + 1
			else:
				break
		if a == b:
			ans = 0
			ans = ans + count // 3
			count = count % 3
			if count == 1 or count == 2:
				ans = ans + 1
			print(ans)
		else:
			print(-1)
	elif b > a:
		while b > a:
			if b % 2 == 0:
				b = b // 2
				count = count + 1
			else:
				break
		if a == b:
			ans = 0
			ans = ans + count // 3
			count = count % 3
			if count == 1 or count == 2:
				ans = ans + 1
			print(ans)
		else:
			print(-1)
	else:
		print(0)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	q = [[a, 0]]
	visit = set()
	if max(a, b) % min(a, b) != 0:
		print(-1)
	else:
		c = 0
		for i in q:
			if i[0] == b:
				print(i[1])
				break
			if i[1] > 25:
				print(-1)
				break
			if i[0] % 8 == 0 and i[0] // 8 not in visit:
				q.append([i[0] // 8, i[1] + 1])
				visit.add(i[0] // 8)
			if i[0] % 4 == 0 and i[0] // 4 not in visit:
				q.append([i[0] // 4, i[1] + 1])
				visit.add(i[0] // 4)
			if i[0] % 2 == 0 and i[0] // 2 not in visit:
				q.append([i[0] // 2, i[1] + 1])
				visit.add(i[0] // 2)
			if i[0] * 2 not in visit:
				q.append([i[0] * 2, i[1] + 1])
				visit.add(i[0] * 2)
			if i[0] * 4 not in visit:
				q.append([i[0] * 4, i[1] + 1])
				visit.add(i[0] * 4)
			if i[0] * 8 not in visit:
				q.append([i[0] * 8, i[1] + 1])
				visit.add(i[0] * 8)


t = int(input())
while t > 0:
	t -= 1
	(a, b) = list(map(int, input().split()))
	k = 0
	if a > b:
		while a % 2 == 0 and a > b:
			a //= 2
			k += 1
	elif a < b:
		while b % 2 == 0 and b > a:
			b //= 2
			k += 1
	if a == b:
		if k % 3 == 0:
			print(k // 3)
		else:
			print(k // 3 + 1)
	else:
		print(-1)


def N():
	return int(input())

def NM():
	return map(int, input().split())

def L():
	return list(NM())

def LN(n):
	return [N() for i in range(n)]

def LL(n):
	return [L() for i in range(n)]
t = N()

def f():
	(a, b) = sorted(NM())
	x = 0
	while b > a:
		if b % 2 != 0:
			print(-1)
			return
		b //= 2
		x += 1
	if b != a:
		print(-1)
	else:
		print((x + 2) // 3)
for i in range(t):
	f()


def swap(x, y):
	return (y, x)
t = int(input())
while t:
	t -= 1
	f = 1
	c = 0
	(a, b) = [int(x) for x in input().split(' ')]
	if a < b:
		(a, b) = swap(a, b)
	while a != b:
		if a % 2 == 0 and a // 2 == b or (a % 4 == 0 and a // 4 == b) or (a % 8 == 0 and a // 8 == b):
			c += 1
			break
		if a % 8 == 0:
			c += 1
			a //= 8
		elif a % 4 == 0:
			c += 1
			a //= 4
		elif a % 2 == 0:
			c += 1
			a //= 2
		else:
			f = 0
			break
	if f:
		print(c)
	else:
		print('-1')


def find_step(q):
	step = 0
	while q % 8 == 0:
		step += 1
		q = q // 8
	while q % 4 == 0:
		step += 1
		q = q // 4
	while q % 2 == 0:
		step += 1
		q = q // 2
	if q > 1:
		return 0
	return step

def main():
	t = int(input())
	for __ in range(t):
		(a, b) = map(int, input().split())
		if b > a and b % a == 0:
			steps = find_step(b // a)
			if steps == 0:
				print(-1)
			else:
				print(steps)
		elif a > b and a % b == 0:
			steps = find_step(a // b)
			if steps == 0:
				print(-1)
			else:
				print(steps)
		elif a == b:
			print(0)
		else:
			print(-1)
main()


def pow2(a):
	while a % 2 == 0:
		a = a // 2
	return a
t = int(input())
for i in range(t):
	(a, b) = list(map(int, input().split()))
	ans = 0
	if pow2(a) != pow2(b):
		print(-1)
	else:
		c = max(a, b)
		d = min(a, b)
		c = c // d
		while c >= 8:
			c = c // 8
			ans += 1
		if c > 1:
			ans += 1
		print(ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if True else 1):
	(a, b) = map(int, input().split())
	if max(a, b) % min(a, b) != 0 or bin(max(a, b) // min(a, b))[3:].count('1') != 0:
		print(-1)
		continue
	from math import log2
	next = int(log2(max(a, b) // min(a, b)))
	print(ceil(next / 3))


t = int(input())
for i in range(t):
	(a11, b11) = map(int, input().split())
	count = 0
	if a11 > b11:
		t = a11
		a11 = b11
		b11 = t
	if a11 == b11:
		print(0)
	else:
		while b11 > a11 * 4 and b11 != a11:
			a11 *= 8
			count += 1
		while b11 > a11 * 2 and b11 != a11:
			a11 *= 4
			count += 1
		while b11 > a11 and b11 != a11:
			a11 *= 2
			count += 1
		if b11 == a11:
			print(count)
		else:
			print(-1)


from math import log
t = int(input())
for _ in range(t):
	(a, b) = sorted(map(int, input().split()))
	if b % a != 0:
		print(-1)
		continue
	q = b // a
	ops = round(log(q, 2))
	if 2 ** ops != q:
		print(-1)
		continue
	print((ops + 2) // 3)


import math
for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	a = max(n, k)
	b = min(n, k)
	ans = 0
	while a > b:
		b <<= 1
		ans += 1
	if a == b:
		print(math.ceil(ans / 3))
	else:
		print(-1)


from math import ceil
n_sets = int(input())
for _ in range(n_sets):
	(a, b) = list(map(int, input().split()))
	(a, b) = (min(a, b), max(a, b))
	if b % a != 0:
		print(-1)
	else:
		k = b // a
		i = 0
		while k != 1 and k % 2 == 0:
			k //= 2
			i += 1
		if k != 1 or b % a != 0:
			print(-1)
		else:
			print(ceil(i / 3))


t = int(input())
for i in range(t):
	(a, b) = [int(a) for a in input().split()]
	count = 0
	if a > b:
		temp = a
		a = b
		b = temp
	while a * 8 <= b:
		a = a * 8
		count = count + 1
	while a * 4 <= b:
		a = a * 4
		count = count + 1
	while a * 2 <= b:
		a = a * 2
		count = count + 1
	if a != b:
		print(-1)
	else:
		print(count)


testing_mode = True
import sys, traceback
test_data = ''
final_output = ''

def input(input_format=0, multi=0):
	if multi > 0:
		return [input(input_format) for x in range(multi)]
	else:
		next_line = next(test_data, None).strip() if test_data else sys.stdin.readline()
		if input_format == 0:
			formatted_input = [next_line]
		elif input_format == 1:
			formatted_input = list(map(int, next_line.split()))
		elif input_format == 2:
			formatted_input = list(map(float, next_line.split()))
		elif input_format == 3:
			formatted_input = next_line.split()
		elif input_format == 4:
			formatted_input = (lambda x: [x[0], list(map(int, x[1:]))])(next_line.split())
		elif input_format == 5:
			formatted_input = (lambda x: [x[0], list(map(float, x[1:]))])(next_line.split())
		else:
			formatted_input = [next_line]
		return formatted_input

def log(*args):
	if testing_mode:
		print(*args)

def out(output_line, output_format=0, newline=True):
	global final_output
	formatted_output = ''
	if output_format == 0:
		formatted_output = str(output_line)
	elif output_format == 1:
		formatted_output = ' '.join(map(str, output_line))
	elif output_format == 1:
		formatted_output = '\n'.join(map(str, output_line))
	if testing_mode:
		final_output += formatted_output + '\n' * newline
	else:
		print(formatted_output, end='\n' if newline else '')
test_inputs = ['\n10\n10 5\n11 44\n17 21\n1 1\n96 3\n2 128\n1001 1100611139403776\n1000000000000000000 1000000000000000000\n7 1\n10 8\n\n', '\n$$$\n', '\n$$$\n', '\n$$$\n']
test_outputs = ['\n1\n1\n-1\n0\n2\n2\n14\n0\n-1\n-1\n\n', '\n$$$\n', '\n$$$\n', '\n$$$\n']

def solve():
	for z in range(input(1)[0]):
		(x, y) = input(1)
		a = min(x, y)
		b = max(x, y)
		log(a, b)
		if b % a != 0:
			out(-1)
			continue
		f = b // a
		c = 0
		while f > 1:
			if f % 8 == 0:
				f //= 8
				c += 1
			elif f % 4 == 0:
				f //= 4
				c += 1
			elif f % 2 == 0:
				f //= 2
				c += 1
			else:
				break
		log(f)
		if f > 1:
			out(-1)
		else:
			out(c)
	return

def run_all(overwrite_testing=False):
	global testing_mode, final_output, test_data
	testing_mode = overwrite_testing and testing_mode
	if testing_mode:
		tests_failed = 0
		for (test_number, (test_in, test_out)) in enumerate(zip(test_inputs, test_outputs)):
			final_output = ''
			if test_in.lstrip()[:3] == '$$$':
				continue
			test_data = iter([i for i in test_in.split('\n') if i])
			print(f'Test Case #{test_number + 1}:')
			print('<' * 20)
			fail = False
			verdict = '\x1b[92m\x1b[1mPASS\x1b[0m'
			try:
				solve()
				final = final_output.rstrip('\n')
				raw_out = iter(map(str, final.split('\n'))) if final else iter(())
			except Exception:
				raw_out = ''
				fail = True
				print('\x1b[95m')
				traceback.print_exc()
				print('\x1b[0m')
			if raw_out:
				if test_out.lstrip()[:3] == '$$$':
					verdict = '\x1b[94m\x1b[1mSKIP\x1b[0m'
					print('\x1b[94m' + '\n'.join(list(raw_out)) + '\x1b[0m')
				else:
					for line_out in [i for i in test_out.split('\n') if i]:
						line_raw = next(raw_out, '% None %')
						if line_raw == line_out.strip():
							print(f'\x1b[92m{line_raw}\x1b[0m')
						else:
							print(f'\x1b[91m{line_raw}\x1b[0m')
							fail = True
					line_raw = next(raw_out, None)
					while line_raw:
						print(f'\x1b[91m{line_raw}\x1b[0m')
						line_raw = next(raw_out, None)
						fail = True
			print('>' * 20)
			if fail:
				verdict = '\x1b[91m\x1b[1mFAIL\x1b[0m'
				tests_failed += 1
			print(verdict + '\n')
		if tests_failed:
			print(f"\x1b[91m\x1b[1m{tests_failed} TEST{('S' if tests_failed > 1 else '')} FAILED!\x1b[0m")
		else:
			print(f'\x1b[92m\x1b[1mALL TESTS PASSED!\x1b[0m')
	else:
		test_data = False
		solve()
run_all(False)


t = int(input())
while t > 0:
	t -= 1
	(a, b) = [int(i) for i in input().split(' ')]
	if a < b:
		(a, b) = (b, a)
	aa = bin(a).replace('0b', '')
	bb = bin(b).replace('0b', '')
	ok = True
	start = 0
	for i in range(start, len(bb)):
		if aa[i] != bb[i]:
			ok = False
			break
	if not ok:
		print(-1)
		continue
	ok = True
	for i in range(len(bb), len(aa)):
		if aa[i] == '1':
			ok = False
			break
	if not ok:
		print(-1)
		continue
	to_cover = len(aa) - len(bb)
	answer = 0
	for i in range(3, 0, -1):
		answer += to_cover // i
		to_cover %= i
	print(answer)


for t in range(int(input())):
	(a, b) = [int(x) for x in input().split()]
	if a == b:
		print('0')
	elif a % 2 == 1 and b % 2 == 1 or (a % 2 == 1 and b < a) or a < b < a * 2 or (a // 2 < b < a):
		print('-1')
	else:
		(x, y) = (0, 0)
		while a % 2 == 0:
			if a % 8 == 0:
				x += 3
				a //= 8
			elif a % 4 == 0:
				x += 2
				a //= 4
			else:
				x += 1
				a //= 2
		while b % 2 == 0:
			if b % 8 == 0:
				y += 3
				b //= 8
			elif b % 4 == 0:
				y += 2
				b //= 4
			else:
				y += 1
				b //= 2
		if a != b:
			print(-1)
		else:
			print(int(abs(x - y) // 3) + (1 if abs(x - y) % 3 else 0))


import os, sys
t = int(input())
for nc in range(t):
	(a, b) = [int(x) for x in input().strip().split()]
	if a % b != 0 and b % a != 0:
		print(-1)
	elif a == b:
		print(0)
	elif a < b:
		c = b // a
		ans = 0
		while c > 1:
			if c >= 8 and c % 8 == 0:
				ans += 1
				c = c // 8
			elif c >= 4 and c % 4 == 0:
				ans += 1
				c = c // 4
			elif c >= 2 and c % 2 == 0:
				ans += 1
				c = c // 2
			else:
				ans = -1
				c = 0
		print(ans)
	else:
		c = a // b
		ans = 0
		while c > 1:
			if c >= 8 and c % 8 == 0:
				ans += 1
				c = c // 8
			elif c >= 4 and c % 4 == 0:
				ans += 1
				c = c // 4
			elif c >= 2 and c % 2 == 0:
				ans += 1
				c = c // 2
			else:
				ans = -1
				c = 0
		print(ans)


def foo(a, b):
	ans = 0
	while b != a:
		if b % 8 == 0 and b // 8 >= a:
			b //= 8
			ans += 1
			continue
		if b % 4 == 0 and b // 4 >= a:
			b //= 4
			ans += 1
			continue
		if b % 2 == 0 and b // 2 >= a:
			b //= 2
			ans += 1
			continue
		return -1
	return ans
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if b < a:
		temp = a
		a = b
		b = temp
	print(foo(a, b))


t = int(input())
while t != 0:
	(a, b) = map(int, input().split())
	t -= 1
	if a == b:
		print(0)
	elif a < b:
		shifts = [3, 2, 1]
		ans = 0
		count = 0
		while a <= b and count < 3:
			if a << shifts[count] <= b:
				a = a << shifts[count]
				ans += 1
			else:
				count += 1
		if a == b:
			print(ans)
		else:
			print(-1)
	elif a > b:
		shifts = [3, 2, 1]
		ans = 0
		count = 0
		while a >= b and count < 3:
			if a >> shifts[count] >= b:
				test_a = str(bin(a))
				if '1' in test_a[-shifts[count]:]:
					count += 1
					continue
				a = a >> shifts[count]
				ans += 1
			else:
				count += 1
		if a == b:
			print(ans)
		else:
			print(-1)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	ans = 0
	while a < b:
		a *= 2
		ans += 1
	if a == b:
		f = ans // 3
		if ans % 3 != 0:
			f += 1
		print(f)
	else:
		print(-1)


from sys import stdin
import math

def main():
	t = int(stdin.readline())
	for _ in range(t):
		(a, b) = map(int, stdin.readline().strip().split())
		ans = 0
		while a != b:
			if a < b:
				if b < a << 1:
					ans = -1
					break
				a = a << 1
			else:
				if a % 2 != 0 or (a % 2 == 0 and b > a >> 1):
					ans = -1
					break
				a = a >> 1
			ans += 1
		if ans != -1 and ans != 0:
			if ans > 3:
				if ans % 3 != 0:
					ans = ans // 3 + 1
				else:
					ans = ans // 3
			else:
				ans = 1
		print(ans)
main()


def solve():
	(a, b) = map(int, input().split())
	if b < a:
		(a, b) = (b, a)
	cnt = 0
	while a < b:
		cnt += 1
		a *= 2
	print(-1 if a != b else (cnt + 2) // 3)
for _ in range(int(input())):
	solve()


import sys
input = sys.stdin.readline
from collections import *
t = int(input())
e = defaultdict(int)
now = 1
for i in range(70):
	e[now] = i
	now *= 2
for _ in range(t):
	(a, b) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	if b % a != 0:
		print(-1)
		continue
	d = b // a
	if d not in e:
		print(-1)
	else:
		print((e[d] + 2) // 3)


import sys
t = int(input())
for _ in range(t):
	(a, b) = map(int, sys.stdin.readline().split())
	if a == b:
		sys.stdout.write('0\n')
	else:
		k = 0
		l = max(a, b)
		f = min(a, b)
		while l % 2 == 0:
			if l == f:
				break
			l = l // 2
			k += 1
		if l == f:
			if k == 0:
				sys.stdout.write('-1\n')
			elif k <= 2:
				sys.stdout.write('1\n')
			elif k % 3 == 0:
				sys.stdout.write(str(k // 3) + '\n')
			else:
				sys.stdout.write(str(k // 3 + 1) + '\n')
		else:
			sys.stdout.write('-1\n')


from sys import stdin
from math import log2
for _ in range(int(stdin.readline())):
	(a, b) = map(int, stdin.readline().split())
	x = max(a, b)
	y = min(a, b)
	if x % y != 0:
		print(-1)
		continue
	k = x // y
	co = 0
	while k % 2 == 0:
		k //= 2
		co += 1
	if k != 1:
		print(-1)
		continue
	print(co // 3 + (co % 3 != 0))


t = int(input())
for _ in range(t):
	(a, b) = [int(x) for x in input().split()]
	(a, b) = (min(a, b), max(a, b))
	if b & 1 and a != b:
		print(-1)
	else:
		s = 0
		temp = a
		while temp < b:
			temp *= 2
			s += 1
		if temp == b:
			eight = s // 3
			s = s % 3
			four = s // 2
			s = s % 2
			two = s
			print(eight + four + two)
		else:
			print(-1)


from decimal import Decimal
import math
t = int(input())
while t:
	t += -1
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	if b % a:
		print(-1)
	else:
		b //= a
		tmp = 0
		while b % 2 == 0:
			b //= 2
			tmp -= -1
		if b != 1:
			print(-1)
		else:
			t1 = tmp // 3
			tmp = tmp % 3
			t2 = tmp // 2
			tmp = tmp % 2
			t3 = tmp
			print(t1 + t2 + t3)


from sys import stdin
input = stdin.readline
for t in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
		continue
	count = 0
	while a != b:
		if a < b:
			if a * 8 <= b:
				a *= 8
				count += 1
			elif a * 4 <= b:
				a *= 4
				count += 1
			elif a * 2 <= b:
				a *= 2
				count += 1
			else:
				count = -1
				break
		elif a % 8 == 0 and a // 8 >= b:
			a //= 8
			count += 1
		elif a % 4 == 0 and a // 4 >= b:
			a //= 4
			count += 1
		elif a % 2 == 0 and a // 2 >= b:
			a //= 2
			count += 1
		else:
			count = -1
			break
	print(count)


t = int(input())
for _ in range(t):
	(a, b) = [int(x) for x in input().strip().split()]
	ar = 0
	br = 0
	while a >> ar & 1 == 0:
		ar += 1
	while b >> br & 1 == 0:
		br += 1
	moves = 0
	if ar > br:
		a = a >> ar - br
		moves = ar - br
	if br > ar:
		a = a << br - ar
		moves = br - ar
	cnt = 0
	cnt += moves // 3
	moves %= 3
	cnt += moves // 2
	moves %= 2
	cnt += moves
	if a == b:
		print(cnt)
	else:
		print(-1)


t = int(input())
while t > 0:
	(a, b) = [int(i) for i in input().split(' ')]
	c = min(a, b)
	d = max(a, b)
	ans = 0
	while c < d:
		c *= 2
		ans += 1
	if c == d:
		print(ans // 3 + ans % 3 // 2 + ans % 3 % 2)
	else:
		print(-1)
	t -= 1


test_case = int(input())
my_list = []
for i in range(test_case):
	my_list.append([int(j) for j in input().split()])
for x in range(test_case):
	a = int(max(my_list[x]))
	b = int(min(my_list[x]))
	total = 0
	y = True
	while y:
		if a == b:
			y = False
		elif a % 8 == 0 and a >> 3 >= b:
			total += 1
			a = a >> 3
		elif a % 4 == 0 and a >> 2 >= b:
			total += 1
			a = a >> 2
		elif a % 2 == 0 and a >> 1 >= b:
			total += 1
			a = a >> 1
		else:
			y = False
			total = -1
	print(total)


import sys, math
from collections import deque

def solve():
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
		return
	if a > b:
		tmp = a
		a = b
		b = tmp
	if b % a == 0:
		x = b // a
		count = 0
		while x % 8 == 0:
			x = x // 8
			count += 1
		while x % 4 == 0:
			x = x // 4
			count += 1
		while x % 2 == 0:
			x = x // 2
			count += 1
		if x > 1:
			print(-1)
		else:
			print(count)
	else:
		print(-1)
	return
for _ in range(int(input())):
	solve()


n = int(input())
for w in range(n):
	(a, b) = map(int, input().split())
	m1 = max(a, b)
	m2 = min(a, b)
	c = 0
	ans = 0
	while m1 != m2:
		if m1 % 2 == 0:
			m1 = m1 // 2
			c += 1
		else:
			break
	if m1 == m2:
		ans = ans + c // 3
		c = c % 3
		ans = ans + c // 2
		c = c % 2
		ans = ans + c
		print(ans)
	else:
		print('-1')


FAST_IO = 1
if FAST_IO:
	import io, sys, atexit
	read = iter(sys.stdin.read().splitlines()).__next__
	_OUTPUT_BUFFER = io.StringIO()
	sys.stdout = _OUTPUT_BUFFER

	@atexit.register
	def write():
		sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
	read = input
readint = lambda : int(read())
readlist = lambda : list(map(int, read().split()))

def solve(A, B):

	def cvt(x):
		e = 0
		while x & 1 == 0:
			x >>= 1
			e += 1
		return (e, x)
	(e1, x1) = cvt(A)
	(e2, x2) = cvt(B)
	if x1 != x2:
		return -1
	(q, r) = divmod(abs(e1 - e2), 3)
	q += r > 0
	return q
for _ in range(readint()):
	print(solve(*readlist()))


x = int(input())

def f():
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	if n < m:
		(n, m) = (m, n)
	t = 0
	if n == 1 and m == 1:
		print(0)
		return
	while True:
		if n == m:
			break
		elif n < m or n % 2 != 0:
			print(-1)
			return
		n //= 2
		t += 1
	p = t // 3
	p += t % 3 // 2
	p += t % 3 % 2
	print(p)
while x:
	f()
	x -= 1


from sys import stdin, stdout, setrecursionlimit
input = stdin.readline

def ispow(a):
	if a == 1:
		return True
	elif a % 2 == 1:
		return False
	else:
		return ispow(a // 2)
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	else:
		if a < b:
			(a, b) = (b, a)
		if a % b != 0 or not ispow(a // b):
			print(-1)
		else:
			x = a // b
			ans = 0
			while x >= 8:
				ans += 1
				x //= 8
			while x >= 4:
				ans += 1
				x //= 4
			while x >= 2:
				ans += 1
				x //= 2
			print(ans)


import math
for i in range(int(input())):
	(a, b) = map(int, input().split())
	count = 0
	count1 = -1
	if a == b:
		print(0)
	else:
		s = max(b, a) // min(a, b)
		while s != 1:
			if s % 2 == 0 and max(b, a) % min(b, a) == 0:
				s = s // 2
				count += 1
			else:
				count = 0
				break
		k = math.ceil(count / 3)
		if k == 0:
			print('-1')
		else:
			print(k)


import math, sys, bisect
from collections import defaultdict, Counter, deque

def input():
	return sys.stdin.readline().strip()
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])
for _ in range(int(input())):
	(a, b) = ilele()
	if a < b:
		(a, b) = (b, a)
	c = 0
	while b * 8 <= a:
		b *= 8
		c += 1
	while b * 4 <= a:
		b *= 4
		c += 1
	while b * 2 <= a:
		b *= 2
		c += 1
	if a == b:
		print(c)
	else:
		print(-1)


def ans(a, b):
	if a == b:
		return 0
	if a < b:
		count = 0
		x = False
		while a * 8 <= b:
			count += 1
			a *= 8
			if a == b:
				x = True
		if x == True:
			return count
		while a * 4 <= b:
			count += 1
			a *= 4
			if a == b:
				x = True
		if x == True:
			return count
		while a * 2 <= b:
			count += 1
			a *= 2
			if a == b:
				x = True
		if x == True:
			return count
		return -1
	if b < a:
		count = 0
		x = False
		while b * 8 <= a:
			count += 1
			b *= 8
			if a == b:
				x = True
		if x == True:
			return count
		while b * 4 <= a:
			count += 1
			b *= 4
			if a == b:
				x = True
		if x == True:
			return count
		while b * 2 <= a:
			count += 1
			b *= 2
			if a == b:
				x = True
		if x == True:
			return count
		return -1
m = int(input())
for i in range(m):
	a = input().split()
	b = int(a[0])
	c = int(a[1])
	print(ans(b, c))


def getOdd(num):
	while num % 2 == 0:
		num //= 2
	return num
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	if getOdd(a) != getOdd(b):
		print(-1)
		continue
	b //= a
	cnt = 0
	while b >= 8:
		b //= 8
		cnt += 1
	if b > 1:
		cnt += 1
	print(cnt)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if b == a:
		print(0)
	elif b < a:
		if a % b != 0:
			print(-1)
		else:
			n = a // b
			i = 0
			while n % 2 ** i == 0:
				i += 1
			if 2 ** (i - 1) != n:
				print(-1)
			elif (i - 1) % 3 == 0:
				print((i - 1) // 3)
			elif (i - 1) % 3 != 0:
				print((i - 1) // 3 + 1)
	elif b > a:
		x = a
		a = b
		b = x
		if a % b != 0:
			print(-1)
		else:
			n = a // b
			i = 0
			while n % 2 ** i == 0:
				i += 1
			if 2 ** (i - 1) != n:
				print(-1)
			elif (i - 1) % 3 == 0:
				print((i - 1) // 3)
			elif (i - 1) % 3 != 0:
				print((i - 1) // 3 + 1)


t = int(input())

def count(a):
	total = 0
	while a % 2 == 0:
		total += 1
		a = a // 2
	return (a, total)
for i in range(t):
	(a, b) = map(int, input().split())
	(x1, y1) = count(a)
	(x2, y2) = count(b)
	if x1 != x2:
		print(-1)
	else:
		print(abs(y1 - y2) // 3 + 1 if abs(y1 - y2) % 3 != 0 else abs(y1 - y2) // 3)


t = int(input())
for o in range(t):
	(a, b) = map(int, input().split())
	if a % b != 0 and b % a != 0:
		print(-1)
	else:
		d = max(a, b) // min(a, b)
		y = 0
		c = 0
		while d != 1:
			if d % 8 == 0:
				d = d // 8
			elif d % 4 == 0:
				d = d // 4
			elif d % 2 == 0:
				d = d // 2
			else:
				print(-1)
				y = 1
				break
			c += 1
		if y == 0:
			print(c)


from sys import stdin, stdout
nmbr = lambda : int(stdin.readline())
lst = lambda : list(map(int, stdin.readline().split()))
for _ in range(nmbr()):
	(src, des) = lst()
	ans = 0
	if src == des:
		print(0)
	elif src < des:
		while src * 8 <= des:
			src *= 8
			ans += 1
		while src * 4 <= des:
			src *= 4
			ans += 1
		while src * 2 <= des:
			src *= 2
			ans += 1
		if src == des:
			print(ans)
		else:
			print(-1)
	else:
		while src % 8 == 0 and src // 8 >= des:
			src //= 8
			ans += 1
		while src % 4 == 0 and src // 4 >= des:
			src //= 4
			ans += 1
		while src % 2 == 0 and src // 2 >= des:
			src //= 2
			ans += 1
		if src == des:
			print(ans)
		else:
			print(-1)


import math
tc = int(input())
for k in range(tc):
	(a, b) = input().split(' ')
	a = int(a)
	b = int(b)
	step = 0
	if a < b:
		c = a
		a = b
		b = c
	while a > b:
		b = b * 2
		step += 1
	if a == b:
		step = (step - 1 + 3) // 3
	else:
		step = -1
	print(int(step))


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	elif a > b:
		flag = 0
		count = 0
		while a != b:
			if a % 8 != 0 or a // 8 < b:
				if a % 4 != 0 or a // 4 < b:
					if a % 2 != 0 or a // 2 < b:
						flag = 1
						break
					else:
						a //= 2
				else:
					a //= 4
			else:
				a //= 8
			count += 1
		if flag == 1:
			print(-1)
		else:
			print(count)
	else:
		flag = 0
		count = 0
		while a != b:
			if 8 * a > b:
				if 4 * a > b:
					if 2 * a > b:
						flag = 1
						break
					else:
						a *= 2
				else:
					a *= 4
			else:
				a *= 8
			count += 1
		if flag == 1:
			print(-1)
		else:
			print(count)


x = int(input())
for xxx in range(x):
	(aaa, bbb) = map(int, input().split())
	if aaa == bbb:
		print(0)
		continue
	elif aaa > bbb:
		iii = 1
		while 1:
			ans = aaa >> iii
			if ans <= bbb:
				break
			else:
				iii += 1
		if ans < bbb:
			print(-1)
			continue
		elif aaa >> iii << iii != aaa:
			print(-1)
			continue
		else:
			p = iii // 3
			iii %= 3
			p += iii // 2
			iii %= 2
			p += iii
			print(p)
	else:
		po = 1
		while 1:
			an = aaa << po
			if an >= bbb:
				break
			else:
				po += 1
		if an > bbb:
			print(-1)
			continue
		else:
			ans = po // 3
			po %= 3
			ans += po // 2
			po %= 2
			ans += po
			print(ans)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	sa = bin(a).replace('0b', '')
	sb = bin(b).replace('0b', '')
	if a == b:
		print(0)
	elif a > b:
		if sb == sa[0:len(sb)]:
			if '1' not in sa[len(sb):]:
				z = len(sa[len(sb):])
				c = 0
				while z - 3 >= 0:
					z -= 3
					c += 1
				while z - 2 >= 0:
					z -= 2
					c += 1
				while z - 1 >= 0:
					z -= 1
					c += 1
				print(c)
			else:
				print(-1)
		else:
			print(-1)
	elif sa == sb[0:len(sa)]:
		if '1' not in sb[len(sa):]:
			z = len(sb[len(sa):])
			c = 0
			while z - 3 >= 0:
				z -= 3
				c += 1
			while z - 2 >= 0:
				z -= 2
				c += 1
			while z - 1 >= 0:
				z -= 1
				c += 1
			print(c)
		else:
			print(-1)
	else:
		print(-1)


import math
for t in range(int(input())):
	(a, b) = map(int, input().split())
	(at, bt) = (a, b)
	while at % 2 == 0:
		at = at // 2
	while bt % 2 == 0:
		bt = bt // 2
	if at != bt:
		print(-1)
	elif a > b:
		p = a / b
		q = math.log(p, 2)
		ans = math.ceil(q / 3)
		print(ans)
	else:
		p = b / a
		q = math.log(p, 2)
		ans = math.ceil(q / 3)
		print(ans)


import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline

def geta(fn=lambda s: s.decode()):
	return map(fn, readline().split())

def gete(fn=lambda s: s.decode()):
	return fn(readline().rstrip())

def main():
	for _ in range(gete(int)):
		(a, b) = geta(int)
		if a < b:
			(a, b) = (b, a)
		if a % b != 0:
			print(-1)
		else:
			t = a // b
			c = 0
			while t & 1 == 0:
				t >>= 1
				c += 1
			c3 = c // 3
			c2 = c % 3
			if t == 1:
				print(c3 + (1 if c2 == 2 else c2))
			else:
				print(-1)
main()


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a <= b:
		k = 0
		while 2 * a <= b:
			a *= 2
			k += 1
		if a == b:
			print((k + 2) // 3)
		else:
			print(-1)
	else:
		d = 0
		i = 0
		res = -1
		flag = False
		while a % 2 == 0:
			a //= 2
			i += 1
			if a == b:
				flag = True
				res = i
				break
		if flag:
			print((res + 2) // 3)
		else:
			print(-1)


def read_int():
	return int(input().strip())

def read_ints():
	return list(map(int, input().strip().split(' ')))

def solve():
	(A, B) = read_ints()
	if A < B:
		(A, B) = (B, A)
	count = 0
	while A > B:
		B *= 2
		count += 1
	if A == B:
		return count // 3 + count % 3 // 2 + count % 3 % 2
	return -1
T = read_int()
for _ in range(T):
	print(solve())


from math import ceil
for _ in range(int(input())):
	(a, b) = [int(i) for i in input().split()]
	if a > b:
		(a, b) = (b, a)
	c = 0
	while b % 2 == 0 and b > a:
		b //= 2
		c += 1
	if a != b:
		print(-1)
	else:
		print(ceil(c / 3))


import math
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	if a == b:
		print('0')
		continue
	if a < b:
		c = a
		a = b
		b = c
	flag = 0
	cnt = 0
	while True:
		b = b * 2
		cnt += 1
		if a == b:
			flag = 1
			break
		if a < b:
			break
	if not flag:
		print('-1')
	else:
		print(math.floor((cnt - 1 + 3) / 3))


import sys
input = sys.stdin.readline
ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda : int(input())
ip = lambda : [int(w) for w in input().split()]
for _ in range(inp()):
	(a, b) = ip()
	(a, b) = (min(a, b), max(a, b))
	if a == b:
		print(0)
		continue
	t = b // a
	if b % a or t & t - 1:
		print(-1)
		continue
	ans = 0
	import math
	t = int(math.log(t, 2))
	ans += t // 3
	t %= 3
	ans += t // 2
	t %= 2
	ans += t
	print(ans)


from sys import stdin
input = stdin.readline
import bisect
import math
for xoxo in range(1):
	for _ in range(int(input())):
		(a, b) = map(int, input().split())
		if a == b:
			print('0')
		else:
			if a < b:
				(a, b) = (b, a)
			if a % b != 0:
				print('-1')
			else:
				x = 0
				while a > b:
					if b * 8 <= a:
						x += 1
						b *= 8
					elif b * 4 <= a:
						x += 1
						b *= 4
					else:
						x += 1
						b *= 2
				if a == b:
					print(x)
				else:
					print('-1')


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	else:
		if a > b:
			(a, b) = (b, a)
		if b % a == 0:
			b = b // a
			a = a // a
		t = 0
		while b % 8 == 0:
			b = b // 8
			t += 1
		if a != b:
			while b % 4 == 0:
				b = b // 4
				t += 1
		if a != b:
			while b % 2 == 0:
				b = b // 2
				t += 1
		if a == b:
			print(t)
		else:
			print(-1)


import math

def primeFactors(n):
	ans = []
	while n % 2 == 0:
		ans.append(2)
		n = n >> 1
	if int(n) != 1:
		return [-1]
	else:
		return ans
from sys import stdin, stdout
q = int(input())
for _ in range(q):
	(a, b) = map(int, stdin.readline().strip().split())
	if a == b:
		print(0)
		continue
	if a < b:
		(a, b) = (b, a)
	if a % b != 0:
		print(-1)
	else:
		pfactors = primeFactors(a // b)
		if pfactors == [-1]:
			print(-1)
		else:
			twos = len(pfactors)
			ans = 0
			(q, r) = divmod(twos, 3)
			ans += q
			twos = r
			(q, r) = divmod(twos, 2)
			ans += q
			twos = r
			(q, r) = divmod(twos, 1)
			ans += q
			print(ans)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	c1 = min(a, b)
	c2 = max(a, b)
	ans = 0
	f = 0
	if c2 == c1:
		print(0)
	elif c2 % c1 == 0:
		q = c2 // c1
		if q % 2 == 0:
			while q > 1:
				if q % 8 == 0:
					q = q // 8
				elif q % 4 == 0:
					q = q // 4
				elif q % 2 == 0:
					q = q // 2
				else:
					f = 1
					break
				ans += 1
			if f == 0:
				print(ans)
			else:
				print(-1)
		else:
			print(-1)
	else:
		print(-1)


import math
test = int(input())
for i in range(test):
	(a, b) = map(int, input().split())
	ans = 0
	if a > b:
		temp = b
		b = a
		a = temp
	no = a
	prev = 0
	while no < b:
		if no * 8 <= b:
			prev = no
			no = no * 8
			ans += 1
		elif no * 4 <= b:
			prev = no
			no = no * 4
			ans += 1
		elif no * 2 <= b:
			prev = no
			no = no * 2
			ans += 1
		else:
			break
	if no != b:
		ans = -1
		print(ans)
	else:
		print(ans)


import sys
import string
input = sys.stdin.readline
import math
t = int(input())
powers = []
for j in range(100):
	powers.append(2 ** j)
for i in range(t):
	m = list(map(int, input().split()))
	(a, b) = (max(m), min(m))
	if a % b != 0:
		print(-1)
	elif a // b not in powers:
		print(-1)
	else:
		x = a / b
		c = powers.index(x)
		print(math.ceil(c / 3))


for k in range(int(input())):
	(a, b) = map(int, input().split())
	count = 0
	if a < b:
		while 8 * a <= b:
			a = a * 8
			count += 1
		while 4 * a <= b:
			a = a * 4
			count += 1
		while 2 * a <= b:
			a = a * 2
			count += 1
		if a == b:
			print(count)
		else:
			print(-1)
	else:
		while a >= b * 8 and a % 8 == 0:
			a = a // 8
			count += 1
		while a >= b * 4 and a % 4 == 0:
			a = a // 4
			count += 1
		while a >= b * 2 and a % 2 == 0:
			a = a // 2
			count += 1
		if b == a:
			print(count)
		else:
			print(-1)


def min_operations(a, b):
	a_without_trailing_zeroes = a
	a_zeroes = 0
	while a_without_trailing_zeroes % 2 == 0:
		a_zeroes += 1
		a_without_trailing_zeroes //= 2
	b_without_trailing_zeroes = b
	b_zeroes = 0
	while b_without_trailing_zeroes % 2 == 0:
		b_zeroes += 1
		b_without_trailing_zeroes //= 2
	if a_without_trailing_zeroes != b_without_trailing_zeroes:
		return -1
	diff = abs(a_zeroes - b_zeroes)
	(moves, rem) = divmod(diff, 3)
	if rem > 0:
		moves += 1
	return moves

def main():
	t = int(input())
	for _ in range(t):
		(a, b) = map(int, input().split())
		print(min_operations(a, b))
main()


from math import log2
T = int(input())
D = []
for i in range(0, T):
	(a, b) = [int(x) for x in input().split(' ')]
	if a < b:
		(a, b) = (b, a)
	m = a / b
	c = int(log2(m) + 1 / 2)
	if 2 ** c * b == a:
		e = c % 3
		if e == 0:
			D.append((c - e) // 3)
		else:
			D.append((c - e) // 3 + 1)
	else:
		D.append(-1)
for i in D:
	print(i)


inp = lambda cast=int: [cast(x) for x in input().split()]
printf = lambda s='', *args, **kwargs: print(str(s).format(*args), flush=True, **kwargs)
(t,) = inp()
for _ in range(t):
	(a, b) = inp()
	if a > b:
		(a, b) = (b, a)
	q = b // a
	if b % a == 0 and q & q - 1 == 0:
		l = len('{:b}'.format(q)) - 1
		res = l // 3 + l % 3 // 2 + l % 3 % 2
	else:
		res = -1
	print(res)


from sys import stdin

def answer(a, b):
	(a, b) = sorted([a, b], reverse=True)
	if a == b:
		return 0
	if a % b != 0:
		return -1
	c = a // b
	twoCount = 0
	while c != 1:
		if c % 2 != 0:
			return -1
		c = c // 2
		twoCount += 1
	count = 0
	if twoCount >= 3:
		count += twoCount // 3
		twoCount = twoCount % 3
	if twoCount >= 2:
		count += twoCount // 2
		twoCount = twoCount % 2
	count += twoCount
	return count
testCount = int(input())
for _ in range(testCount):
	(a, b) = map(int, stdin.readline().split())
	print(answer(a, b))


t = int(input())
while t:
	t -= 1
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	if b % a == 0:
		k = b // a
		x = 0
		y = 0
		z = 0
		f = 1
		while k > 1:
			if k % 8 == 0:
				x += 1
				k = k // 8
			elif k % 4 == 0:
				y += 1
				k = k // 4
			elif k % 2 == 0:
				z += 1
				k = k // 2
			else:
				f = 0
				break
		if f:
			print(x + y + z)
		else:
			print(-1)
	else:
		print(-1)


t = int(input())
while t > 0:
	flag = 0
	count = 0
	(a, b) = map(int, input().split())
	while a != b:
		if a > b:
			if a % 8 == 0 and a // 8 >= b:
				a //= 8
				count += 1
			elif a % 4 == 0 and a // 4 >= b:
				a //= 4
				count += 1
			elif a % 2 == 0:
				a //= 2
				count += 1
			else:
				flag = 1
				break
			if a < b:
				flag = 1
				break
		else:
			if a * 8 <= b:
				a *= 8
				count += 1
			elif a * 4 <= b:
				a *= 4
				count += 1
			elif a * 2 <= b:
				a *= 2
				count += 1
			else:
				flag = 1
				break
			if a > b:
				flag = 1
				break
	if flag == 1:
		print('-1')
	else:
		print(count)
	t -= 1


st = ''
import math
from functools import reduce
from bisect import bisect_left, bisect, bisect_right
from itertools import accumulate
from math import sqrt
from math import gcd
from bisect import bisect_left, bisect, bisect_right
from sys import setrecursionlimit
setrecursionlimit(10 ** 6)

def func(a, b):
	p = 0
	if a > b:
		while a > b:
			if a & 1 == 0:
				a = a >> 1
				p += 1
			elif a == b:
				q = p % 3
				if q > 0:
					q = 1
				return min(p // 3 + q, p // 2 + p % 2)
			else:
				return -1
	elif a < b:
		while a < b:
			a = a << 1
			p += 1
			if a == b:
				q = p % 3
				if q > 0:
					q = 1
				return min(p // 3 + q, p // 2 + p % 2)
		if a > b:
			return -1
	else:
		return 0
	if a == b:
		q = p % 3
		if q > 0:
			q = 1
		return min(p // 3 + q, p // 2 + p % 2)
	else:
		return -1
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	st += str(func(a, b)) + '\n'
print(st)


t = int(input())
while t:
	(a, b) = list(map(int, input().split()))
	c = 0
	if a > b:
		m1 = a
		m2 = b
	else:
		m1 = b
		m2 = a
	b1 = bin(m1)[2:]
	b2 = bin(m2)[2:]
	i = 0
	flag = 0
	while i < len(b2):
		if b1[i] != b2[i]:
			flag = 1
			c = -1
			break
		i += 1
	else:
		l = len(b2)
		if l < len(b1):
			x = b1[l:]
			for i in x:
				if i != '0':
					flag = 1
					c = -1
					break
			else:
				count = len(x)
				d = 2 ** count
				c = 0
				while d % 8 == 0:
					d = d // 8
					c += 1
				while d % 4 == 0:
					d = d // 4
					c += 1
				while d % 2 == 0:
					d = d // 2
					c += 1
		elif m1 == m2:
			c = 0
		else:
			c = -1
	print(c)
	t -= 1


def main():
	t = int(input())
	for _ in range(t):
		(a, b) = map(int, input().split())
		if b > a:
			(a, b) = (b, a)
		if a % b != 0:
			print(-1)
			continue
		total = 0
		scale = a // b
		while True:
			if scale % 8 == 0:
				total += 1
				scale //= 8
			else:
				break
		while True:
			if scale % 4 == 0:
				total += 1
				scale //= 4
			else:
				break
		while True:
			if scale % 2 == 0:
				total += 1
				scale //= 2
			else:
				break
		if scale != 1:
			print(-1)
		else:
			print(total)
main()


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop
import math
from collections import *
from functools import reduce, cmp_to_key, lru_cache
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
M = mod = 10 ** 9 + 7

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip().split()]

def st():
	return str(input().rstrip())[2:-1]

def val():
	return int(input().rstrip())

def li2():
	return [str(i)[2:-1] for i in input().rstrip().split()]

def li3():
	return [int(i) for i in st()]
for _ in range(val()):
	(a, b) = li()
	ans = 0
	if b >= a:
		while a < b:
			if a * 8 <= b:
				a *= 8
			elif a * 4 <= b:
				a *= 4
			elif a * 2 <= b:
				a *= 2
			else:
				ans = -2
				a = b
			ans += 1
	else:
		while a > b:
			if not a % 8 and a // 8 >= b:
				a //= 8
			elif not a % 4 and a // 4 >= b:
				a //= 4
			elif not a % 2 and a // 2 >= b:
				a //= 2
			else:
				ans = -2
				a = b
			ans += 1
	print(ans)


from math import log2, floor

def ispower(x):
	temp = 2 ** floor(log2(x))
	if temp == x:
		return True
	return False
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if b == a:
		print(0)
		continue
	if a > b:
		(a, b) = (b, a)
	if b % a != 0:
		print(-1)
		continue
	if ispower(b // a) == False:
		print(-1)
		continue
	temp = floor(log2(b // a))
	ans = temp // 3
	temp = temp % 3
	ans += temp // 2
	temp %= 2
	ans += temp
	print(ans)


ll = lambda : map(int, input().split())
t = lambda : int(input())
ss = lambda : input()
lx = lambda x: map(int, input().split(x))
from math import log10, log2, ceil, factorial as fac, gcd
for _ in range(t()):
	(n, k) = ll()
	(n, k) = (min(n, k), max(n, k))
	c = 0
	while 8 * n <= k:
		n *= 8
		c += 1
	while 4 * n <= k:
		n *= 4
		c += 1
	while n * 2 <= k:
		n *= 2
		c += 1
	if n != k:
		print(-1)
	else:
		print(c)


from decimal import Decimal

class Problem1362A:

	def solve(a, b):
		c = 0
		if a == b:
			return 0
		if a > b:
			while a > b:
				if a % 8 == 0 and a / 8 >= b:
					a = a / 8
					c += 1
				elif a % 4 == 0 and a / 4 >= b:
					a = a / 4
					c += 1
				elif a % 2 == 0 and a / 2 >= b:
					a = a / 2
					c += 1
				else:
					break
		else:
			while a < b:
				if a * 8 <= b:
					a = a * 8
					c += 1
				elif a * 4 <= b:
					a = a * 4
					c += 1
				elif a * 2 <= b:
					a = a * 2
					c += 1
				else:
					break
		if a == b:
			return c
		return -1

	def main():
		t = int(input())
		for i in range(0, t):
			a = input()
			a = a.split(' ')
			print(Problem1362A.solve(Decimal(a[0]), Decimal(a[1])))
Problem1362A.main()


for p in range(int(input())):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	ans = 0
	if a > b:
		while a % 8 == 0 and a // 8 >= b:
			a //= 8
			ans += 1
		while a % 4 == 0 and a // 4 >= b:
			ans += 1
			a //= 4
		while a % 2 == 0 and a // 2 >= b:
			ans += 1
			a //= 2
	if a < b:
		while a * 8 <= b:
			ans += 1
			a *= 8
		while a * 4 <= b:
			ans += 1
			a *= 4
		while a * 2 <= b:
			ans += 1
			a *= 2
	if a == b:
		print(ans)
	else:
		print(-1)


for i in range(int(input())):
	(num, target) = map(int, input().split())
	if target < num:
		(target, num) = (num, target)
	if target % num == 0:
		temp = target // num
		ans = 0
		while temp % 8 == 0 and temp != 1:
			ans += 1
			temp //= 8
		while temp % 4 == 0 and temp != 1:
			ans += 1
			temp //= 4
		while temp % 2 == 0 and temp != 1:
			ans += 1
			temp //= 2
		if temp == 1:
			print(ans)
		else:
			print(-1)
	else:
		print(-1)


import math
t = int(input())
while t > 0:
	(a, b) = map(int, input().split())
	count = 0
	if a == b:
		print('0')
	else:
		if a > b:
			(a, b) = (b, a)
		while a < b:
			a = a * 2
			count = count + 1
		if b == a:
			total = 0
			if count > 0:
				temp = count // 3
				count = count - temp * 3
				total += temp
				temp = count // 2
				count = count - temp * 2
				total += temp
				total += count
			print(total)
		else:
			print('-1')
	t -= 1


import sys
import math

def input():
	return sys.stdin.readline().rstrip()
t = int(input())
answers = []

def pow_of_2(a):
	x = 1
	power = 0
	for i in range(100):
		if x == a:
			return (True, power)
		x = 2 * x
		power = power + 1
	return (False, -1)
for _ in range(t):
	(a, b) = [int(i) for i in input().split()]
	(a, b) = (min(a, b), max(a, b))
	if a == b:
		ans = 0
	elif b % a != 0:
		ans = -1
	else:
		aim = b // a
		(success, power) = pow_of_2(aim)
		if not success:
			ans = -1
		else:
			ans = power // 3
			rem = power % 3
			ans += rem // 2
			ans += rem % 2
	answers.append(ans)
print(*answers, sep='\n')


import sys
import math
input = sys.stdin.readline

def inp():
	return int(input())

def inara():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return list(map(int, input().split()))
t = inp()
for _ in range(t):
	(a, b) = invr()
	if a < b:
		(a, b) = (b, a)
	if a % b:
		print(-1)
		continue
	ans = 0
	a //= b
	while a % 8 == 0:
		a //= 8
		ans += 1
	while a % 4 == 0:
		a //= 4
		ans += 1
	while a % 2 == 0:
		a //= 2
		ans += 1
	if a != 1:
		print(-1)
	else:
		print(ans)


t = int(input())
for jack in range(t):
	(n, m) = map(int, input().split())
	if m > n:
		(n, m) = (m, n)
	p = 0
	while n % 2 == 0 and n > m:
		p += 1
		n = n // 2
	if n == m:
		y = p // 3 + p % 3 // 2 + p % 3 % 2
		print(y)
	else:
		print(-1)


from math import log2
for _ in range(int(input())):
	(a, b) = [int(p) for p in input().split()]
	M = max(a, b)
	m = min(a, b)
	if M % m != 0:
		print(-1)
		continue
	elif M == m:
		print(0)
		continue
	else:
		v = log2(M // m)
		if m * 2 ** int(v) != M:
			print(-1)
			continue
		else:
			count = 0
			count += v // 3
			v -= 3 * (v // 3)
			count += v // 2
			v -= 2 * (v // 2)
			count += v
	print(int(count))


import math
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	k = 0
	while a * 8 <= b:
		k += 1
		a *= 8
	while a * 4 <= b:
		k += 1
		a *= 4
	while a * 2 <= b:
		k += 1
		a *= 2
	if a == b:
		print(k)
	else:
		print(-1)


import math
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	c2 = 0
	c4 = 0
	c8 = 0
	if b > a:
		(a, b) = (b, a)
	x = a // b
	if a % b == 0:
		if x == 1:
			print(0)
		else:
			ss = 0
			while x > 1:
				if x % 8 == 0:
					x = x // 8
					ss += 1
				elif x % 4 == 0:
					x = x // 4
					ss += 1
				elif x % 2 == 0:
					x = x // 2
					ss += 1
				else:
					ss = -1
					break
			print(ss)
	else:
		print(-1)


def jac(n, k):
	c = 0
	if n == k:
		print(0)
		return
	elif n > k:
		while n > k:
			if n % 8 == 0 and n // 8 >= k:
				n = n // 8
				c = c + 1
			elif n % 4 == 0 and n // 4 >= k:
				n = n // 4
				c = c + 1
			elif n % 2 == 0 and n // 2 >= k:
				n = n // 2
				c = c + 1
			else:
				print(-1)
				return
		if n == k:
			print(c)
			return
		else:
			print(-1)
			return
	else:
		while k > n:
			if k % 8 == 0 and k // 8 >= n:
				k = k // 8
				c = c + 1
			elif k % 4 == 0 and k // 4 >= n:
				k = k // 4
				c = c + 1
			elif k % 2 == 0 and k // 2 >= n:
				k = k // 2
				c = c + 1
			else:
				print(-1)
				return
		if k == n:
			print(c)
			return
		else:
			print(-1)
			return
t = int(input())
for i in range(t):
	T = input()
	l = list(map(int, T.split()))
	jac(l[0], l[1])


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	res = 0
	while a < b:
		if a * 8 <= b:
			a *= 8
		elif a * 4 <= b:
			a *= 4
		else:
			a *= 2
		res += 1
	if a == b:
		print(res)
	else:
		print(-1)


import math

def big(a, b):
	v = math.log2(b / a)
	if math.floor(v) != math.ceil(v):
		return -1
	v = math.floor(v)
	if b != a * pow(2, v):
		return -1
	steps = 0
	d = 3
	while v > 0:
		(ans, v) = divmod(v, d)
		steps += ans
		d -= 1
	return steps
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	elif b > a:
		print(big(a, b))
	else:
		print(big(b, a))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	(p, q) = (min(a, b), max(a, b))
	if p == q:
		print(0)
	elif q % p != 0 or q & 1 == 1:
		print(-1)
	else:
		if int(q / p) % 2 != 0:
			print(-1)
			continue
		(ans, flag) = (0, 0)
		while p != q:
			if 8 * p <= q:
				p *= 8
				ans += 1
			elif 4 * p <= q:
				p *= 4
				ans += 1
			elif 2 * p <= q:
				p *= 2
				ans += 1
			else:
				print(-1)
				flag = 1
				break
		if not flag:
			print(ans)


iterations = int(input())
for i in range(iterations):
	(a, b) = map(int, input().split())
	a = bin(a)
	b = bin(b)
	if a[a.find('1'):a.rfind('1') + 1] == b[b.find('1'):b.rfind('1') + 1]:
		diff = abs(a[::-1].find('1') - b[::-1].find('1'))
		if diff % 3 != 0:
			print(int(diff // 3 + 1))
		else:
			print(int(diff / 3))
	else:
		print(-1)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
import sys

def solve(a, b):
	if a % b != 0:
		return -1
	d = a // b
	cnt = 0
	while d > 1:
		if d % 2 != 0:
			return -1
		d //= 2
		cnt += 1
	return (cnt + 2) // 3

def main():
	mod = 1000000007
	inv = lambda x: pow(x, mod - 2, mod)
	t = int(input())
	for _ in range(t):
		(a, b) = map(int, input().split())
		if a < b:
			(a, b) = (b, a)
		ans = solve(a, b)
		sys.stdout.write(str(ans) + '\n')
main()


import sys, math, cmath, time
start_time = time.time()

def solve():
	ONLINE_JUDGE_SOLUTION = CodeforcesSolutions.AutoSolve('1362', 'A', 'GET', 'POST')

def main():
	global tt
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	t = inp()
	for tt in range(t):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
	sys.stdout.close()

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	return input().strip()

def invr():
	return map(int, input().split())

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = q[a[i] - 1] + 1
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q

def log2(x):
	return math.log10(x) / math.log10(2)

def power_two(n):
	sttr = str(n)
	len_str = len(sttr)
	sttr = list(sttr)
	num = 0
	if len_str == 1 and sttr[len_str - 1] == '1':
		return 0
	while len_str != 1 or sttr[len_str - 1] != '1':
		if (ord(sttr[len_str - 1]) - ord('0')) % 2 == 1:
			return 0
		j = 0
		for i in range(len_str):
			num = num * 10 + (ord(sttr[i]) - ord('0'))
			if num < 2:
				if i != 0:
					sttr[j] = '0'
					j += 1
				continue
			sttr[j] = chr(num // 2 + ord('0'))
			j += 1
			num = num - num // 2 * 2
		len_str = j
	return 1

class CodeforcesSolutions:

	def AutoSolve(contest_id, question_id, get, post):
		(a, b) = invr()
		if a == 1 and b == 1:
			print(0)
			return
		if a == 1 or b == 1:
			q = max(a, b)
			if True:
				if power_two(q):
					qqww = math.ceil(log2(q))
					w = qqww // 3
					qw = qqww % 3
					qq = qw // 2
					ww = qw % 2
					print(w + qq + ww)
				else:
					print(-1)
			return
		if a > b:
			if a // b == a / b and power_two(a // b):
				q = math.ceil(log2(a // b))
				w = q // 3
				qw = q % 3
				qq = qw // 2
				ww = qw % 2
				print(w + qq + ww)
			else:
				print(-1)
		elif b > a:
			(a, b) = (b, a)
			if a // b == a / b and power_two(a // b):
				q = math.ceil(log2(a // b))
				w = q // 3
				qw = q % 3
				qq = qw // 2
				ww = qw % 2
				print(w + qq + ww)
			else:
				print(-1)
		else:
			print(0)
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


def solve(a, b):
	ans = 0
	if a == b:
		return 0
	elif a > b:
		if a % b == 0 and a // b % 2 == 0:
			num = a // b
			while num > 1:
				if num % 2 != 0:
					return -1
				if num % 8 == 0:
					num = num // 8
					ans += 1
					continue
				if num % 4 == 0:
					num = num // 4
					ans += 1
					continue
				if num % 2 == 0:
					num = num // 2
					ans += 1
					continue
			return ans
		else:
			return -1
	elif b % a == 0 and b // a % 2 == 0:
		num = b // a
		while num > 1:
			if num % 2 != 0:
				return -1
			if num % 8 == 0:
				num = num // 8
				ans += 1
				continue
			if num % 4 == 0:
				num = num // 4
				ans += 1
				continue
			if num % 2 == 0:
				num = num // 2
				ans += 1
				continue
		return ans
	else:
		return -1
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	print(solve(a, b))


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	a = bin(a)[2:]
	b = bin(b)[2:]
	ind1 = len(a) - 1
	ind2 = len(b) - 1
	while a[ind1] == '0':
		ind1 -= 1
	while b[ind2] == '0':
		ind2 -= 1
	a2 = a[:ind1 + 1]
	b2 = b[:ind2 + 1]
	if a2 != b2:
		print(-1)
	else:
		x = abs(len(a) - len(b))
		ans = x // 3
		x %= 3
		ans += x // 2
		x %= 2
		ans += x
		print(ans)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if max(a, b) % min(a, b) != 0:
		print(-1)
	else:
		bit = max(a, b) // min(a, b)
		counter = 0
		while bit > 1:
			if bit % 2 != 0:
				counter = -1
				break
			else:
				bit //= 2
				counter += 1
		if counter != -1:
			print(counter // 3 + counter % 3 // 2 + counter % 3 % 2)
		else:
			print(-1)


import math
from collections import defaultdict, Counter, deque
INF = float('inf')

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def primeFactor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i ** 2 <= n:
		if n % i == 0:
			return i
		i += 1
	return n

def main():
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	cnt = 0
	while a != b:
		if a * 8 <= b:
			a *= 8
		elif a * 4 <= b:
			a *= 4
		else:
			a *= 2
		if a > b:
			cnt = -1
			break
		cnt += 1
	print(cnt)
t = int(input())
for _ in range(t):
	main()


import math

def solution():
	for _ in range(int(input())):
		(a, b) = map(int, input().split())
		if a == b:
			print(0)
		else:
			z = a * b // math.gcd(a, b)
			cnt = 0
			x = z // a
			y = z // b
			flag = 0
			while x != 1:
				if x % 8 == 0:
					x //= 8
				elif x % 4 == 0:
					x //= 4
				elif x % 2 == 0:
					x //= 2
				else:
					flag = 1
					break
				cnt += 1
			while y != 1:
				if y % 8 == 0:
					y //= 8
				elif y % 4 == 0:
					y //= 4
				elif y % 2 == 0:
					y //= 2
				else:
					flag = 1
					break
				cnt += 1
			if flag == 1:
				print(-1)
			else:
				print(cnt)
solution()


from sys import stdin
input = lambda : stdin.readline().strip()
char = [chr(i) for i in range(97, 123)]
CHAR = [chr(i) for i in range(65, 91)]
mp = lambda : list(map(int, input().split()))
INT = lambda : int(input())
rn = lambda : range(INT())
mod = 10000000007
from math import ceil, sqrt, factorial, gcd
for _ in rn():
	(a, b) = mp()
	(a, b) = (max(a, b), min(a, b))
	ans = 0
	if a % b == 0 and a // b % 2 == 0:
		h = a // b
		while h % 8 == 0:
			ans += 1
			h //= 8
		while h % 4 == 0:
			ans += 1
			h //= 4
		while h % 2 == 0:
			ans += 1
			h //= 2
		if h == 1:
			print(ans)
		else:
			print(-1)
	elif a == b:
		print(0)
	else:
		print(-1)


def solve(a, b):
	c = 0
	while a < b:
		a = a * 8
		c += 1
	if a == b or a // 4 == b or a // 2 == b:
		return c
	return -1
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	ans = solve(a, b)
	print(ans)


from collections import defaultdict as dd
import math
import sys
import string
input = sys.stdin.readline

def nn():
	return int(input())

def li():
	return list(input())

def mi():
	return map(int, input().split())

def lm():
	return list(map(int, input().split()))
q = nn()
for _ in range(q):
	(a, b) = mi()
	small = min(a, b)
	big = max(a, b)
	ops = 0
	while small < big:
		small *= 2
		ops += 1
	if small == big:
		print((ops + 2) // 3)
	else:
		print(-1)


t = int(input())
for _ in range(0, t):
	(n, m) = map(int, input().split())
	count = 0
	if n == 1 or m == 1:
		z = max(n, m)
		y = min(n, m)
		flag = 0
		if z == 1 and y == 1:
			print(0)
		elif z % 8 == 0 or z % 4 == 0 or z % 2 == 0:
			while z != 1:
				if z % 8 == 0:
					z = z // 8
					count += 1
				elif z % 4 == 0:
					z = z // 4
					count += 1
				elif z % 2 == 0:
					z = z // 2
					count += 1
				else:
					flag = 1
					break
			if flag == 1:
				print(-1)
			else:
				print(count)
		else:
			print(-1)
	elif n % m == 0 or m % n == 0:
		z = max(n, m)
		y = min(n, m)
		z = z // y
		flag = 0
		while z != 1:
			if z % 8 == 0:
				z = z // 8
				count += 1
			elif z % 4 == 0:
				z = z // 4
				count += 1
			elif z % 2 == 0:
				z = z // 2
				count += 1
			else:
				flag = 1
				break
		if flag == 0:
			print(count)
		else:
			print(-1)
	else:
		print(-1)


for _ in range(int(input())):
	(a, b) = list(map(int, input().split()))
	if a == b:
		print(0)
	elif a > b:
		if a % b == 0:
			k = a // b
			cnt = z = 0
			while k != 1:
				if k % 8 == 0:
					cnt += 1
					k = k // 8
				elif k % 4 == 0:
					cnt += 1
					k = k // 4
				elif k % 2 == 0:
					cnt += 1
					k = k // 2
				else:
					z = 1
					break
			if z:
				print(-1)
			else:
				print(cnt)
		else:
			print(-1)
	elif b % a == 0:
		k = b // a
		cnt = z = 0
		while k != 1:
			if k % 8 == 0:
				cnt += 1
				k = k // 8
			elif k % 4 == 0:
				cnt += 1
				k = k // 4
			elif k % 2 == 0:
				cnt += 1
				k = k // 2
			else:
				z = 1
				break
		if z:
			print(-1)
		else:
			print(cnt)
	else:
		print(-1)


import math

def check(s1, s2):
	if s1[0:len(s2)] == s2:
		k = len(s1) - len(s2)
		print('k:', k)
		count = 0
		for i in range(len(s2), len(s1)):
			if s1[i] == '0':
				count += 1
		if count == k:
			print(math.ceil(count / 3))
		else:
			print(-1)
	else:
		print('monish')
		print(-1)
t = int(input())
while t:
	l = list(map(int, input().strip().split()))[:2]
	(val, tar) = (l[0], l[1])
	if l[0] == l[1]:
		print(0)
	else:
		t1 = ''
		t2 = ''
		n1 = val
		n2 = tar
		while n1 > 0:
			t1 += str(n1 % 2)
			n1 //= 2
		t1 = t1[::-1]
		while n2 > 0:
			t2 += str(n2 % 2)
			n2 //= 2
		t2 = t2[::-1]
		if val > tar:
			if t1[0:len(t2)] == t2:
				k = len(t1) - len(t2)
				count = 0
				for i in range(len(t2), len(t1)):
					if t1[i] == '0':
						count += 1
				if count == k:
					print(math.ceil(count / 3))
				else:
					print(-1)
			else:
				print(-1)
		elif t2[0:len(t1)] == t1:
			k = len(t2) - len(t1)
			count = 0
			for i in range(len(t1), len(t2)):
				if t2[i] == '0':
					count += 1
			if count == k:
				print(math.ceil(count / 3))
			else:
				print(-1)
		else:
			print(-1)
	t -= 1


import math
n = int(input())
while n:
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	else:
		mn = min(a, b)
		mx = max(a, b)
		c = 0
		while mx > mn:
			mn *= 2
			c += 1
		if mx == mn:
			print(math.ceil(c / 3))
		else:
			print(-1)
	n -= 1


n = int(input())
for line in range(n):
	line = input()
	line = line.split()
	a = int(line[0])
	b = int(line[1])
	count = 0
	flag = True
	flag1 = False
	while b >= a:
		flag1 = True
		if b == a:
			break
		elif b // 2 < a or b % 2 != 0:
			break
		elif b % 8 == 0 and b // 8 >= a:
			b //= 8
			count += 1
		elif b % 4 == 0 and b // 4 >= a:
			b //= 4
			count += 1
		elif b % 2 == 0 and b // 2 >= a:
			b //= 2
			count += 1
	if flag1 == True and b != a:
		flag = False
	while a >= b and flag1 == False:
		if a == b:
			break
		elif a // 2 < b or a % 2 != 0:
			break
		elif a % 8 == 0 and a // 8 >= b:
			a //= 8
			count += 1
		elif a % 4 == 0 and a // 4 >= b:
			a //= 4
			count += 1
		elif a % 2 == 0 and a // 2 >= b:
			a //= 2
			count += 1
	if flag1 == False and a != b:
		flag = False
	if flag == False:
		print(-1)
	else:
		print(count)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split(' '))
	if a == b:
		print(0)
	elif a < b:
		if b % a == 0:
			x = b // a
			ans = 0
			q = [8, 4, 2]
			i = 0
			while i < 3 and x > 1:
				while x % q[i] == 0:
					ans += 1
					x = x // q[i]
				i += 1
			if x > 1:
				print(-1)
			else:
				print(ans)
		else:
			print(-1)
	elif a % b == 0:
		x = a // b
		ans = 0
		q = [8, 4, 2]
		i = 0
		while i < 3 and x > 1:
			while x % q[i] == 0:
				ans += 1
				x = x // q[i]
			i += 1
		if x > 1:
			print(-1)
		else:
			print(ans)
	else:
		print(-1)


tc = int(input())
for _ in range(tc):
	(a, b) = map(int, input().split())
	ans = 0
	if a < b:
		if b % 2 == 1:
			ans = -1
		elif b % a == 0:
			tmp = b // a
			cnt = 0
			check = False
			while tmp % 2 == 0:
				cnt += 1
				tmp = tmp // 2
				if tmp % 2 != 0 and tmp != 1:
					check = True
			if cnt == 0 or check:
				ans = -1
			else:
				while 0 < cnt:
					cnt -= 3
					ans += 1
		else:
			ans = -1
	elif a == b:
		ans = 0
	elif a % 2 == 1:
		ans = -1
	elif a % 2 == 1:
		ans = -1
	elif a % b == 0:
		tmp = a // b
		cnt = 0
		check = False
		while tmp % 2 == 0:
			cnt += 1
			tmp = tmp // 2
			if tmp % 2 != 0 and tmp != 1:
				check = True
		if cnt == 0 or check:
			ans = -1
		else:
			while 0 < cnt:
				cnt -= 3
				ans += 1
	else:
		ans = -1
	print(ans)


def read_int():
	return int(input())

def read_ints():
	return map(int, input().split(' '))
t = read_int()
for case_num in range(t):
	(a, b) = read_ints()
	if a == b:
		print(0)
		continue
	elif a < b:
		tmp = a
		a = b
		b = tmp
	if a % b != 0:
		print(-1)
		continue
	c = a // b
	t = 0
	ok = True
	while c >= 2:
		if c % 2 == 0:
			c //= 2
			t += 1
		else:
			ok = False
			break
	print((t - 1) // 3 + 1 if ok else -1)


for _ in range(int(input())):
	(a, b) = [int(i) for i in input().split()]
	a = bin(a)
	b = bin(b)
	i = len(a) - 1
	while a[i] == '0':
		i -= 1
	aftA = i + 1
	i = len(b) - 1
	while b[i] == '0':
		i -= 1
	aftB = i + 1
	if b[:aftB] != a[:aftA]:
		print('-1')
	else:
		calc = abs(len(a) - aftA - (len(b) - aftB))
		calc = calc // 3 + (1 if calc % 3 != 0 else 0)
		print(calc)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	(r1, r2) = (a, b)
	while r1 % 2 == 0:
		r1 //= 2
	while r2 % 2 == 0:
		r2 //= 2
	if r1 != r2:
		print(-1)
	else:
		ans = 0
		b //= a
		while b > 8:
			b //= 8
			ans += 1
		if b > 1:
			ans += 1
		print(ans)


def main():
	t = int(input())
	for _ in range(t):
		(a, b) = map(int, input().split())
		if a == b:
			print(0)
			continue
		else:
			if b > a:
				(a, b) = (b, a)
			if a % b != 0:
				print(-1)
				continue
			else:
				cnt = 0
				while a > b:
					if a % 2 == 0:
						a = a // 2
						cnt += 1
					else:
						print(-1)
						break
				else:
					print(cnt // 3 + cnt % 3 // 2 + cnt % 3 % 2 if a == b else -1)
main()


for t in range(int(input())):
	(a, b) = map(int, input().split())
	ans = 0
	if a == b:
		print(0)
	else:
		if b > a:
			(a, b) = (b, a)
		ba = bin(a)[2:]
		lena = len(ba)
		bb = bin(b)[2:]
		lenb = len(bb)
		flag = 1
		ind = ba.find(bb)
		if ind > 0 or ind == -1:
			print(-1)
		else:
			res = ba[lenb:][::-1]
			while res != '':
				if res.find('000') == 0:
					ans += 1
					res = res[3:]
				elif res.find('00') == 0:
					ans += 1
					res = res[2:]
				elif res.find('0') == 0:
					ans += 1
					res = res[1:]
				else:
					flag = -1
					break
			if flag == -1:
				print(-1)
			else:
				print(ans)


from math import log2
t = int(input())
results = []
for case in range(t):
	(a, b) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	n = 0
	while a < b:
		n += 1
		a = a << 3
	if a == b or a >> 1 == b or a >> 2 == b:
		ans = n
	else:
		ans = -1
	results.append(ans)
for result in results:
	print(result)


from math import log2 as l
for _ in range(int(input())):
	(a, b) = list(map(int, input().split()))
	na = int(l(a - (a & a - 1)))
	nb = int(l(b - (b & b - 1)))
	a >>= na
	b >>= nb
	if a == b:
		if na == nb:
			print(0)
		else:
			print(int((abs(na - nb) - 1) / 3) + 1)
	else:
		print(-1)


import math
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	big = a
	small = b
	if b > a:
		big = b
		small = a
	if big == small:
		print(0)
	elif big % small != 0:
		print(-1)
	else:
		flag = 0
		temp = big // small
		count = 0
		while temp != 1:
			count += 1
			if temp % 2 == 0:
				temp = temp // 2
			else:
				flag = 1
				print(-1)
				break
		if flag == 1:
			continue
		elif count % 3 == 0:
			print(count // 3)
		else:
			print(count // 3 + 1)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if b > a:
		if b % a != 0:
			print('-1')
		else:
			x = bin(b // a)[2:].count('1')
			if x != 1:
				print('-1')
			else:
				y = bin(b // a)[2:].count('0')
				ans = 0
				ans += y // 3
				y = y - y // 3 * 3
				ans += y // 2
				y = y - y // 2 * 2
				ans += y
				print(ans)
	elif a > b:
		(a, b) = (b, a)
		if b % a != 0:
			print('-1')
		else:
			x = bin(b // a)[2:].count('1')
			if x != 1:
				print('-1')
			else:
				y = bin(b // a)[2:].count('0')
				ans = 0
				ans += y // 3
				y = y - y // 3 * 3
				ans += y // 2
				y = y - y // 2 * 2
				ans += y
				print(ans)
	else:
		print('0')


T = int(input())
for _ in range(T):
	(x, y) = map(int, input().split())
	(ans, c) = (0, 0)
	if x == y:
		ans = 0
	else:
		a = max(x, y)
		b = min(x, y)
		while b < a:
			b = b * 2
			c += 1
		if b != a:
			ans = -1
		elif c % 3 == 0:
			ans = c // 3
		else:
			ans = c // 3 + 1
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	if n < m:
		(n, m) = (m, n)
	if n % m == 0:
		x = n // m
		b = 0
		while x % 2 == 0:
			x //= 2
			b += 1
		if x != 1:
			print(-1)
		else:
			print((b + 2) // 3)
	else:
		print(-1)


import math
t = int(input())

def number_of_nulls(a):
	cnt = 0
	while a & 1 == 0:
		a >>= 1
		cnt += 1
	return cnt

def can(a, b):
	while a & 1 == 0:
		a >>= 1
	while b & 1 == 0:
		b >>= 1
	if a == b:
		return True
	else:
		return False
while t > 0:
	(a, b) = map(int, input().split())
	if can(a, b):
		number_of_nulls_a = number_of_nulls(a)
		number_of_nulls_b = number_of_nulls(b)
		print(math.ceil(abs(number_of_nulls_b - number_of_nulls_a) / 3))
	else:
		print(-1)
	t -= 1


import os
import sys
import io
import math
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
for t in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
		continue
	if a % b == 0 or b % a == 0:
		required = max(a, b) // min(a, b)
		count = 0
		while required != 1:
			if required % 8 == 0:
				required //= 8
			elif required % 4 == 0:
				required //= 4
			elif required % 2 == 0:
				required //= 2
			else:
				count = -1
				break
			count += 1
		print(count)
	else:
		print(-1)


import math
t = int(input())
an = []
for i in range(t):
	(a, b) = map(int, input().split())
	if b > a:
		(a, b) = (b, a)
	if a % b != 0 or a == 0 or b == 0:
		an.append(-1)
	else:
		m = a // b
		c = 0
		while m % 8 == 0:
			m = m // 8
			c = c + 1
		if m % 4 == 0:
			c = c + 1
			m = m // 4
		elif m % 2 == 0:
			c = c + 1
			m = m // 2
		if m == 1:
			an.append(c)
		else:
			an.append(-1)
print('\n'.join(map(str, an)))


from sys import stdin, stdout
from math import log2
for _ in range(int(stdin.readline())):
	(a, b) = map(int, stdin.readline().split())
	if a == b:
		stdout.write('0\n')
		continue
	if a < b:
		(a, b) = (b, a)
	if a % b:
		stdout.write('-1\n')
		continue
	a //= b
	if a & a - 1 != 0:
		stdout.write('-1\n')
		continue
	ans = int(log2(a))
	ans = ans // 3 + (1 if ans % 3 else 0)
	stdout.write(str(ans) + '\n')


for i in range(int(input())):
	(n, a) = map(int, input().split())
	(n, a) = (max(n, a), min(n, a))
	c = 0
	while a < n:
		a = a * 8
		c += 1
	if a == n or a // 4 == n or a // 2 == n:
		print(c)
	else:
		print(-1)


import math

def main():
	for q in range(int(input())):
		(A, B) = map(int, input().split())
		if A >= B:
			temp = B
			B = A
			A = temp
		c = 0
		while A < B:
			if A * 8 <= B:
				A *= 8
			elif A * 4 <= B:
				A *= 4
			elif A * 2 <= B:
				A *= 2
			else:
				break
			c += 1
		if A == B:
			print(c)
		else:
			print(-1)
main()


from sys import stdout, stdin

def main():
	for t in range(int(stdin.readline())):
		(a, b) = map(int, stdin.readline().split())
		if b > a:
			if b % a != 0:
				print(-1)
			else:
				c = b // a
				i = 8
				op = 0
				while c > 1 and i >= 2:
					if c % i == 0:
						c = c // i
						op += 1
					else:
						i = i // 2
				if op == 0 or c != 1:
					op = -1
				print(op)
		elif b < a:
			if a % b != 0:
				print(-1)
			else:
				c = a // b
				i = 8
				op = 0
				while c > 1 and i >= 2:
					if c % i == 0:
						c = c // i
						op += 1
					else:
						i = i // 2
				if op == 0 or c != 1:
					op = -1
				print(op)
		else:
			print(0)
main()


import math
import collections
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect_left as bsl
from bisect import bisect_right as bsr
import heapq as hq
setrecursionlimit(2 ** 20)
t = int(stdin.readline())
for _ in range(t):
	(a, b) = list(map(int, stdin.readline().rstrip().split()))
	(a, b) = (min(a, b), max(a, b))
	if a == b:
		ans = 0
	elif b % a != 0:
		ans = -1
	else:
		tmp = b // a
		if bin(tmp).count('1') != 1:
			ans = -1
		else:
			cnt = 0
			while b != a:
				b = b // 2
				cnt += 1
			ans = cnt // 3
			cnt = cnt % 3
			ans += cnt // 2
			cnt = cnt % 2
			ans += cnt
	print(ans)


n = int(input())
for _ in range(n):
	p = list(map(int, input().rstrip().split(' ')))
	c1 = 0
	c2 = 0
	while p[0] % 2 == 0:
		p[0] = p[0] // 2
		c1 += 1
	while p[1] % 2 == 0:
		p[1] = p[1] // 2
		c2 += 1
	if p[1] != p[0]:
		print(-1)
	else:
		z = abs(c1 - c2) // 3
		if abs(c1 - c2) % 3:
			z = z + 1
		print(z)


t = int(input())
for w in range(t):
	inp = input().split()
	a = int(inp[0])
	b = int(inp[1])
	if a > b:
		(a, b) = (b, a)
	count = 0
	while a < b:
		a = a * 8
		count += 1
	if a == b or a // 4 == b or a // 2 == b:
		print(count)
	else:
		print(-1)


from math import log2

def solution(a, b):
	if a > b:
		if a % b != 0:
			return -1
		else:
			div = a // b
	elif b % a != 0:
		return -1
	else:
		div = b // a
	power = 0
	while div != 1:
		if div % 2 != 0:
			return -1
		div = div // 2
		power += 1
	op = 0
	op += power // 3
	power = power % 3
	op += power // 2
	op += power % 2
	return op

def main():
	t = int(input())
	for _ in range(t):
		(a, b) = map(int, input().split())
		print(solution(a, b))
main()


for ii in range(int(input())):
	(a, b) = map(int, input().split())
	c = 0
	if a == b:
		print(0)
	elif a > b:
		if a % b != 0:
			print(-1)
		else:
			r = a // b
			while r != 1:
				if r % 8 == 0:
					r //= 8
					c += 1
				elif r % 4 == 0:
					r //= 4
					c += 1
				elif r % 2 == 0:
					r //= 2
					c += 1
				if r != 1 and r % 2 != 0:
					c = -1
					break
			print(c)
	elif b % a != 0:
		print(-1)
	else:
		r = b // a
		while r != 1:
			if r % 8 == 0:
				r //= 8
				c += 1
			elif r % 4 == 0:
				r //= 4
				c += 1
			elif r % 2 == 0:
				r //= 2
				c += 1
			if r != 1 and r % 2 != 0:
				c = -1
				break
		print(c)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	smaller = min(a, b)
	bina = bin(smaller)[2:]
	binb = bin(a + b - smaller)[2:]
	ans = -1
	lena = len(bina)
	lenb = len(binb)
	if binb == '0' * (lenb - lena) + bina or binb == bina + '0' * (lenb - lena):
		d = lenb - lena
		ans = d // 3 + d % 3 // 2 + d % 3 % 2
	print(ans)


from sys import stdin
input = stdin.readline

def main():
	test = int(input())
	for _ in range(test):
		(a, b) = [int(i) for i in input().split(' ')]
		if a == b:
			print(0)
		elif a > b:
			if a % b != 0:
				print(-1)
			else:
				c = 0
				a = a // b
				while a % 8 == 0:
					c += 1
					a = a // 8
				while a % 4 == 0:
					c += 1
					a = a // 4
				while a % 2 == 0:
					c += 1
					a = a // 2
				if a != 1:
					print(-1)
				else:
					print(c)
		elif b % a != 0:
			print(-1)
		else:
			c = 0
			b = b // a
			while b % 8 == 0:
				c += 1
				b = b // 8
			while b % 4 == 0:
				c += 1
				b = b // 4
			while b % 2 == 0:
				c += 1
				b = b // 2
			if b != 1:
				print(-1)
			else:
				print(c)
main()


t = int(input())
for i in range(t):
	s = list(map(int, input().split()))
	(a, b) = (s[0], s[1])
	c = min(a, b)
	d = max(a, b)
	k = 0
	while c < d:
		c = c * 2
		k += 1
	if c == d:
		print(k // 3 + k % 3 // 2 + k % 3 % 2)
	else:
		print(-1)


import sys
import math
import random

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def tinput():
	return input().split()

def linput():
	return list(input())

def rinput():
	return map(int, tinput())

def rlinput():
	return list(map(int, input().split()))

def srlinput():
	return sorted(list(map(int, input().split())))

def main():
	(a, b) = rinput()
	if b < a:
		(a, b) = (b, a)
	if b % a:
		print(-1)
		return
	b //= a
	res = 0
	while b % 8 == 0:
		res += 1
		b //= 8
	if b == 2 or b == 4:
		res += 1
		b = 1
	if b != 1:
		res = -1
	print(res)
for inytd in range(iinput()):
	main()


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if b > a:
		(a, b) = (b, a)
	if a % b != 0:
		print(-1)
		continue
	else:
		z = a // b
		s = 0
		while z != 1:
			if z % 8 == 0:
				z = z // 8
			elif z % 4 == 0:
				z = z // 4
			elif z % 2 == 0:
				z = z // 2
			else:
				s = -1
				break
			s = s + 1
	print(s)


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 19
MOD = 10 ** 9 + 7

def bfs(src, N):
	from collections import deque
	que = deque([src])
	dist = {}
	dist[src] = 0
	while que:
		u = que.popleft()
		for x in [2, 4, 8]:
			if u % x == 0:
				v = u // x
				if v not in dist:
					dist[v] = dist[u] + 1
					que.append(v)
			if u * x <= N:
				v = u * x
				if v not in dist:
					dist[v] = dist[u] + 1
					que.append(v)
	return dist
for _ in range(INT()):
	(a, b) = MAP()
	res = bfs(a, b)
	if b not in res:
		print(-1)
	else:
		print(res[b])


for t in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	else:
		if a < b:
			temp = a
			a = b
			b = temp
		ans = 0
		while b < a:
			if a // 8 >= b and a % 8 == 0:
				ans += 1
				a = a // 8
			elif a // 4 >= b and a % 4 == 0:
				ans += 1
				a = a // 4
			elif a // 2 >= b and a % 2 == 0:
				ans += 1
				a = a // 2
			else:
				break
		if a == b:
			print(ans)
		else:
			print(-1)


import math
for _ in range(int(input())):
	(a, b) = map(int, input().strip().split())
	(a, b) = (max(a, b), min(a, b))
	n = a // b
	if n * b != a:
		print(-1)
		continue
	p = n.bit_length() - 1
	if n != 1 << p:
		print(-1)
		continue
	total = 0
	for i in range(3, 0, -1):
		total += p // i
		p -= p // i * i
	print(total)


def decimal_to_binary(n):
	return [int(s) for s in bin(n).replace('0b', '')]

def Count_no_one(arr):
	c = 0
	for i in arr:
		if i == 1:
			c += 1
	return c
t = int(input())
while t:
	t -= 1
	(a, b) = [int(s) for s in input().split()]
	binA = decimal_to_binary(a)
	binB = decimal_to_binary(b)
	count_one_a = Count_no_one(binA)
	count_one_b = Count_no_one(binB)
	if a == b:
		print(0)
	elif count_one_a != count_one_b:
		print(-1)
	elif a < b:
		if binA == binB[:len(binA)]:
			remaining_zero = len(binB) - len(binA)
			ans = int(remaining_zero / 3)
			if remaining_zero % 3 != 0:
				ans = ans + 1
			print(ans)
		else:
			print(-1)
	elif binB == binA[:len(binB)]:
		remaining_zero = len(binA) - len(binB)
		ans = int(remaining_zero / 3)
		if remaining_zero % 3 != 0:
			ans = ans + 1
		print(ans)
	else:
		print(-1)


def solve(a, b):
	p = b / a
	if p % 1 != 0 or p / 2 % 1 != 0:
		return -1
	c = 0
	while b > a and b % 2 == 0:
		b = b // 2
		c += 1
	if b == a:
		if c % 3 == 0:
			return c // 3
		else:
			return c // 3 + 1
	return -1
for _ in range(int(input())):
	(a, b) = sorted(map(int, input().split()))
	if a == b:
		print(0)
	else:
		print(solve(a, b))


for i in range(int(input())):
	(a, b) = map(int, input().split())
	m = 0
	l = 0
	while a % 2 == 0:
		a //= 2
		m += 1
	while b % 2 == 0:
		b //= 2
		l += 1
	if b != a:
		print(-1)
	else:
		u = abs(l - m)
		if u % 3 != 0:
			print(u // 3 + 1)
		else:
			print(u // 3)


for nt in range(int(input())):
	(a, b) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	ans = 0
	while a < b:
		a = a * 8
		ans += 1
	if a == b:
		print(ans)
	elif a // 4 == b or a // 2 == b:
		print(ans)
	else:
		print(-1)


t = int(input())
for i in range(t):
	(a, b) = list(map(int, input().split()))
	if a == b:
		print(0)
	else:
		if a > b:
			(a, b) = (b, a)
		s1 = bin(b)
		s2 = bin(a)
		try:
			if not s1.index(s2) == 0:
				print(-1)
				continue
		except ValueError:
			print(-1)
			continue
		s1 = s1[len(s2):]
		if '1' in s1:
			print(-1)
			continue
		l = len(s1)
		if l % 3 == 0:
			print(l // 3)
		else:
			print(1 + l // 3)


for t in range(int(input())):
	(a, b) = map(int, input().split())
	ans = 0
	if a > b:
		if a % b == 0:
			c = a // b
			while c % 8 == 0:
				c = c // 8
				ans += 1
			if c == 4:
				c = c // 4
				ans += 1
			elif c == 2:
				c = c // 2
				ans += 1
			if c != 1:
				ans = -1
		else:
			ans = -1
	elif a < b:
		if b % a == 0:
			c = b // a
			while c % 8 == 0:
				c = c // 8
				ans += 1
			if c == 4:
				c = c // 4
				ans += 1
			elif c == 2:
				c = c // 2
				ans += 1
			if c != 1:
				ans = -1
		else:
			ans = -1
	print(ans)


for _ in range(int(input())):
	(n, res) = map(int, input().split())
	(n, res) = (max(n, res), min(n, res))
	ans = 0
	while n > res:
		res *= 8
		ans += 1
	if res == n or res // 4 == n or res // 2 == n:
		print(ans)
	else:
		print(-1)


t = int(input())
while t > 0:
	t = t - 1
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	if a == b:
		print(0)
		continue
	if b > a:
		(a, b) = (b, a)
	if a % 2 != 0:
		print(-1)
		continue
	c = 0
	while a % 2 == 0 and a != b:
		a = a // 2
		c = c + 1
	if a != b:
		print(-1)
		continue
	else:
		ans = 0
		ans += c // 3
		c = c % 3
		ans += c // 2
		c = c % 2
		ans += c
		print(ans)


n = int(input())
for i in range(n):
	out = 0
	(a, b) = map(int, input().split())
	if b > a:
		(a, b) = (b, a)
	if a == b:
		print(0)
		continue
	while True:
		befa = a
		if a % 2 == 0:
			a //= 2
			if a == b:
				out += 1
				print(out)
				break
		a = befa
		if a % 4 == 0:
			a //= 4
			if a == b:
				out += 1
				print(out)
				break
		a = befa
		if a % 8 == 0:
			a //= 8
			out += 1
			if a == b:
				print(out)
				break
		else:
			print(-1)
			break


t = int(input())
matrix = []
for i in range(t):
	aa = input().split()
	matrix.append(aa)
for items in matrix:
	answer = 0
	a = int('{:b}'.format(int(items[0])))
	b = int('{:b}'.format(int(items[1])))
	for i in range(len(str(min(a, b))), len(str(max(a, b)))):
		if str(max(a, b))[i] == '1':
			answer = -1
			break
	if answer != -1:
		for i in range(len(str(min(a, b)))):
			if str(max(a, b))[i] != str(min(a, b))[i]:
				answer = -1
				break
	if answer != -1:
		x = len(str(max(a, b))) - len(str(min(a, b)))
		if x % 3 == 0:
			answer = x / 3
		else:
			answer = x // 3 + 1
	print(int(answer))


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	(x, y) = (0, 0)
	while not a & 1 << x:
		x += 1
	while not b & 1 << y:
		y += 1
	a >>= x
	b >>= y
	if a == b:
		print((abs(x - y) + 2) // 3)
	else:
		print(-1)


for _ in range(int(input())):
	(a, b) = sorted(map(int, input().split()))
	count = 0
	c3 = 0
	flag = 0
	if a == b:
		print(0)
		continue
	if b % a != 0:
		print(-1)
		continue
	while a < b:
		a = a * 2
		count += 1
	if a != b:
		print(-1)
		continue
	while count > 0:
		if count >= 3:
			count -= 3
			flag += 1
		elif count == 2:
			count -= 2
			flag += 1
		else:
			count -= 1
			flag += 1
	print(flag)


import math

def solve_case():
	(a, b) = map(int, input().split())
	if a == b:
		return 0
	if a < b:
		(a, b) = (b, a)
	if a % b != 0:
		return -1
	t = a // b
	base = int(math.log(t, 2))
	if 2 ** base != t:
		return -1
	if base % 3 == 0:
		return base // 3
	return base // 3 + 1

def main():
	tests = int(input())
	for t in range(tests):
		print(solve_case())
main()


from collections import defaultdict
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
		continue
	count = 0
	f = 0
	if a > b:
		(a, b) = (b, a)
	while b > a:
		if a * 8 <= b:
			a = a * 8
		elif a * 4 <= b:
			a = a * 4
		elif a * 2 <= b:
			a = a * 2
		else:
			break
		count += 1
	if a == b:
		print(count)
	else:
		print(-1)


for t in range(int(input())):
	(a, b) = map(int, input().split())
	if a % b == 0:
		rem = a // b
		ct = 0
		while rem % 8 == 0:
			ct += 1
			rem //= 8
		while rem % 4 == 0:
			ct += 1
			rem //= 4
		while rem % 2 == 0:
			ct += 1
			rem //= 2
		if rem == 1:
			print(ct)
		else:
			print(-1)
	elif b % a == 0:
		rem = b // a
		ct = 0
		while rem % 8 == 0:
			ct += 1
			rem //= 8
		while rem % 4 == 0:
			ct += 1
			rem //= 4
		while rem % 2 == 0:
			ct += 1
			rem //= 2
		if rem == 1:
			print(ct)
		else:
			print(-1)
	else:
		print(-1)


import math
import os
import random
import re
import sys

def get_bin_str(n):
	res = []
	rr = 100
	for i in range(rr):
		if n >> i & 1:
			res.append(1)
		else:
			res.append(0)
	res = res[::-1]
	zero_l = 0
	zero_r = 0
	for i in range(rr):
		if res[i] == 1:
			break
		zero_l += 1
	for i in range(rr - 1, -1, -1):
		if res[i] == 1:
			break
		zero_r += 1
	return (res, zero_l, zero_r)
t = int(input())
while t > 0:
	t -= 1
	(a, b) = map(int, input().split())
	(resa, la, ra) = get_bin_str(a)
	(resb, lb, rb) = get_bin_str(b)
	resa = resa[la:100 - ra]
	resb = resb[lb:100 - rb]
	if len(resa) == len(resb):
		is_same = True
		for i in range(len(resa)):
			if resa[i] != resb[i]:
				is_same = False
				break
		if not is_same:
			print(-1)
			continue
		else:
			d = abs(ra - rb)
			print(d // 3 + d % 3 // 2 + d % 3 % 2)
	else:
		print(-1)


T = int(input())
arr = [8, 4, 2]
for _ in range(T):
	(a, b) = list(map(int, input().split()))
	(x, y) = (max(a, b), min(a, b))
	ct = 0
	if x == y:
		print(ct)
	elif x % y != 0:
		print(-1)
	else:
		x = x // y
		if x % 8 != 0 and x % 4 != 0 and (x % 2 != 0):
			print(-1)
		else:
			for v in arr:
				while x % v == 0:
					x = x // v
					ct += 1
			if x != 1:
				print(-1)
			else:
				print(ct)


import math
t = int(input())
for case in range(t):
	[a, b] = sorted(list(map(int, input().split())))
	if b % a != 0:
		print(-1)
	else:
		power = 0
		fact = b // a
		while fact > 1:
			if fact % 2 == 1:
				print(-1)
				power = -1
				break
			else:
				power += 1
				fact = fact // 2
		if power >= 0:
			if power % 3 == 0:
				print(power // 3)
			else:
				print(power // 3 + 1)


cases = int(input())
import math
from decimal import Decimal
for i in range(cases):
	line1 = input().split(' ')
	ini = Decimal(line1[0])
	fin = Decimal(line1[1])
	x = 0
	while ini % 2 == 0:
		if ini % 8 == 0:
			x += 3
			ini = Decimal(ini / 8)
			continue
		if ini % 4 == 0:
			x += 2
			ini = Decimal(ini / 4)
			continue
		if ini % 2 == 0:
			x += 1
			ini = Decimal(ini / 2)
			continue
	y = 0
	while fin % 2 == 0:
		if fin % 8 == 0:
			y += 3
			fin = Decimal(fin / 8)
			continue
		if fin % 4 == 0:
			y += 2
			fin = Decimal(fin / 4)
			continue
		if fin % 2 == 0:
			y += 1
			fin = Decimal(fin / 2)
			continue
	if ini != fin:
		print(-1)
		continue
	elif ini == fin and x == y:
		print(0)
	else:
		distance = abs(x - y)
		moves = math.ceil(distance / 3)
		print(moves)


import math
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if b == a:
		print(0)
	elif b > a:
		if b % a == 0:
			c = str(bin(b // a).replace('0b', ''))
			n = len(c)
			if c == '1' + '0' * (n - 1):
				x = n - 1
				print(x // 3 + x % 3 // 2 + x % 3 % 2)
			else:
				print(-1)
		else:
			print(-1)
	elif a % b == 0:
		c = str(bin(a // b).replace('0b', ''))
		n = len(c)
		if c == '1' + '0' * (n - 1):
			x = n - 1
			print(x // 3 + x % 3 // 2 + x % 3 % 2)
		else:
			print(-1)
	else:
		print(-1)


t = int(input())
for case in range(t):
	y = [str(bin(int(x)))[2:] for x in input().split(' ')]
	y.sort(key=len)
	ans = 0
	if y[0] == y[1][:len(y[0])] and (len(y[0]) == len(y[1]) or '1' not in y[1][len(y[0]):]):
		x = len(y[1]) - len(y[0])
		ans += x // 3
		x = x % 3
		ans += x // 2
		x = x % 2
		ans += x
	else:
		ans = -1
	print(ans)


for q in range(int(input())):
	(a, b) = map(int, input().split())
	da = 0
	db = 0
	while a % 2 == 0:
		a //= 2
		da += 1
	while b % 2 == 0:
		b //= 2
		db += 1
	if a != b:
		print(-1)
	else:
		print((abs(da - db) + 2) // 3)


from math import log
for i in range(int(input())):
	(a, b) = list(map(int, input().split()))
	(a, b) = (max([a, b]), min([a, b]))
	if a == b:
		c = 0
	elif a % b == 0:
		if a // b - 2 ** int(log(a // b, 2)) == 0:
			c = 0
			tmp = a // b
			j = 8
			while j >= 2:
				if tmp != 1:
					k = int(log(tmp, j))
					c += k
					n = j ** k
					if k != 0:
						tmp /= n
				j //= 2
		else:
			c = -1
	else:
		c = -1
	print(c)


def solve():
	(a, b) = map(int, input().split())
	x = max(a, b)
	y = min(a, b)
	if x % y:
		print(-1)
		return
	d = x // y
	if d == 1:
		print(0)
		return
	if bin(d).count('1') > 1:
		print(-1)
		return
	t = len(bin(d)) - 3
	ans = 0
	while t >= 3:
		t -= 3
		ans += 1
	while t >= 2:
		t -= 2
		ans += 1
	while t >= 1:
		t -= 1
		ans += 1
	print(ans)
t = int(input())
for i in range(t):
	solve()


from math import *
from sys import stdin, stdout
input = stdin.buffer.readline
t = int(input())
while t > 0:
	(a, b) = [int(x) for x in input().split()]
	x = max(a, b)
	y = min(a, b)
	if x % y != 0:
		print(-1)
	else:
		flag = 0
		ans = 0
		z = x // y
		while z != 1 and z >= 8:
			if z % 8 != 0:
				flag = 1
				break
			z = z // 8
			ans += 1
		while z != 1 and z >= 4:
			if z % 4 != 0:
				flag = 1
				break
			z = z // 4
			ans += 1
		while z != 1 and z >= 2:
			if z % 2 != 0:
				flag = 1
				break
			z = z // 2
			ans += 1
		if flag == 1:
			print(-1)
		else:
			print(ans)
	t -= 1


def ct(x, y):
	return x // y

def f(x, y):
	if x % y != 0:
		print(-1)
		return
	j = x // y
	if j & j - 1 != 0:
		print(-1)
		return
	res = 0
	while x > y:
		if x // 8 >= y:
			x //= 8
		elif x // 4 >= y:
			x //= 4
		else:
			x //= 2
		res += 1
	print(res)

def sol():
	(x, y) = map(int, input().split())
	if x == y:
		print(0)
		return
	if x > y:
		f(x, y)
	else:
		f(y, x)
for n in range(int(input())):
	sol()


import math
t = int(input())
for _ in range(t):
	(a, b) = tuple(map(int, input().split()))
	ans = 0
	boro = max(a, b)
	choto = min(a, b)
	while choto < boro:
		choto *= 2
		ans += 1
	if choto != boro:
		print(-1)
	elif boro % 8 == 0:
		print(math.ceil(ans / 3))
	elif boro % 4 == 0 and boro % 8 != 0:
		print(math.ceil(ans / 2))
	else:
		print(math.ceil(ans))


import sys
import heapq
import random
import collections
import math

def solve(a, b):
	console('----- solving ------')
	(a, b) = sorted([a, b])
	aa = bin(a)[2:]
	bb = bin(b)[2:]
	console(aa, bb)
	if aa.strip('0') != bb.strip('0'):
		return -1
	diff = len(bb) - len(aa)
	res = diff // 3
	if diff % 3 != 0:
		res += 1
	return int(res)

def console(*args):
	print('\x1b[36m', *args, '\x1b[0m', file=sys.stderr)
	return
for case_num in range(int(input())):
	(a, b) = list(map(int, input().split()))
	res = solve(a, b)
	print(res)


import math

def check(a, b):
	if a % b != 0:
		return -1
	arr = [3, 2, 1]
	n = a // b
	if n & n - 1 != 0:
		return -1
	cnt = 0
	if a == b:
		return 0
	while n:
		n //= 2
		cnt += 1
	cnt -= 1
	ans = 0
	for i in arr:
		ans += cnt // i
		cnt = cnt % i
	return ans
t = int(input())
while t:
	(a, b) = list(map(int, input().split()))
	if b > a:
		(a, b) = (b, a)
	print(check(a, b))
	t -= 1


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	else:
		if a > b:
			(a, b) = (b, a)
		if b % a != 0:
			print(-1)
		else:
			q = b // a
			ans = 0
			am = False
			while q != 1:
				if q % 2 != 0:
					am = True
					break
				q //= 2
				ans += 1
			if am:
				print(-1)
			else:
				print((ans + 2) // 3)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	else:
		(a, b) = (max(a, b), min(a, b))
		c = 0
		f = 0
		while a > b:
			if a % 2 == 0:
				a //= 2
			else:
				f = 1
				break
			c += 1
		if f:
			print(-1)
		elif a == b:
			left = c % 3
			c = c // 3
			c += left // 2
			left = left % 2
			print(c + left)
		else:
			print(-1)


import math

def inp():
	return int(input())

def inlist():
	return list(map(int, input().split()))

def instr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
t = inp()
for _ in range(t):
	(a, b) = invr()
	if a > b:
		(a, b) = (b, a)
	if b % a != 0:
		print('-1')
	else:
		count = 0
		remain = b // a
		while remain > 0:
			if remain % 8 == 0:
				count += 1
				remain //= 8
			elif remain % 4 == 0:
				count += 1
				remain //= 4
			elif remain % 2 == 0:
				count += 1
				remain = remain // 2
			else:
				break
		if remain > 1:
			print(-1)
		else:
			print(count)


def main_function():
	from sys import stdin
	from sys import stdout
	input = stdin.readline
	print = stdout.write
	for _ in range(int(input())):
		(a, b) = sorted(map(int, input().split()))
		(a, b) = (str(bin(a)), str(bin(b)))
		ans = 0
		res = b.replace(a, '')
		ans += res.count('000')
		res = res.replace('000', '')
		ans += res.count('00')
		res = res.replace('00', '')
		ans += res.count('0')
		res = res.replace('0', '')
		print(f'{ans}\n') if res == '' else print(f'{-1}\n')
main_function()


import math
L = math.log
t = int(input())
for _ in range(t):
	l1 = [int(x) for x in input().split()]
	(start, finish) = (l1[0], l1[1])
	if start == finish:
		print(0)
	elif start % 2 and finish % 2:
		print(-1)
	else:
		smol = min(finish, start)
		big = max(finish, start)
		targ = big // smol
		if True:
			targ = len(str(bin(targ))[3:])
			final = smol * 8 ** int(targ / 3) * 4 ** int(targ % 3 / 2) * 2 ** int(targ % 3 % 2)
			if final != big:
				print(-1)
			else:
				print(int(targ / 3) + int(targ % 3 / 2) + int(targ % 3 % 2))


def solve():
	arr = list(map(int, input().split()))
	arr.sort()
	(a, b) = (arr[0], arr[1])
	if a == b:
		print(0)
		return
	elif b % a != 0:
		print(-1)
		return
	else:
		c = 0
		while a < b:
			a = a * 8
			c += 1
			if a == b or a // 2 == b or a // 4 == b:
				print(c)
				return
		print(-1)
t = int(input())
for i in range(0, t):
	solve()


from sys import stdin, setrecursionlimit, stdout
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin

def ii():
	return int(stdin.readline())

def fi():
	return float(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def fmi():
	return map(float, stdin.readline().split())

def li():
	return list(mi())

def si():
	return stdin.readline().rstrip()

def lsi():
	return list(si())
res = ['Yes', 'No']
pow = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824, 2147483648, 4294967296, 8589934592, 17179869184, 34359738368, 68719476736, 137438953472, 274877906944, 549755813888, 1099511627776, 2199023255552, 4398046511104, 8796093022208, 17592186044416, 35184372088832, 70368744177664, 140737488355328, 281474976710656, 562949953421312, 1125899906842624, 2251799813685248, 4503599627370496, 9007199254740992, 18014398509481984, 36028797018963968, 72057594037927936, 144115188075855872, 288230376151711744, 576460752303423488, 1152921504606846976, 2305843009213693952, 4611686018427387904, 9223372036854775808}
test_case = ii()
while test_case:
	test_case -= 1
	(n, k) = mi()
	if n < k:
		(n, k) = (k, n)
	x = -1
	if not n % k and n // k in pow:
		n //= k
		x = 0
		while not n % 8:
			n //= 8
			x += 1
		while not n % 4:
			n //= 4
			x += 1
		while not n % 2:
			n //= 2
			x += 1
	print(x)


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	cnt = 0
	while a < b:
		a = a * 8
		cnt += 1
	if a == b:
		print(cnt)
	elif a // 4 == b or a // 2 == b:
		print(cnt)
	else:
		print(-1)


from math import ceil
dp = []

def solve(a):
	global dp
	x = 0
	while a != 0 and a % 2 == 0:
		a //= 2
		x += 1
	dp.append(x)
	return a

def sol(a, b):
	n = max(a, b)
	m = min(a, b)
	if n % m:
		return -1
	n = n // m
	op = 0
	while n % 8 == 0:
		n //= 8
		op += 1
	while n % 4 == 0:
		n //= 4
		op += 1
	while n % 2 == 0:
		n //= 2
		op += 1
	if n == 1:
		return op
	return -1
k = int(input())
for i in range(k):
	(a, b) = list(map(int, input().split(' ')))
	print(sol(a, b))


import math
t = int(input())
for _ in range(t):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	try:
		if b < a:
			if a % b == 0 and b * 2 ** int(math.log(a // b, 2)) == a:
				m = int(math.log(a // b, 2))
				print(m // 3 + m % 3 // 2 + m % 3 % 2 // 1)
			else:
				raise Exception
		elif b == a:
			print(0)
		elif b % a == 0 and a * 2 ** int(math.log(b // a, 2)) == b:
			m = int(math.log(b // a, 2))
			print(m // 3 + m % 3 // 2 + m % 3 % 2 // 1)
		else:
			raise Exception
	except:
		print('-1')


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	minn = min(a, b)
	maxx = max(a, b)
	if maxx % minn == 0:
		c = 0
		flag = 1
		r = maxx // minn
		while r > 1:
			if r % 8 == 0:
				r = r // 8
				c += 1
			elif r % 4 == 0:
				r = r // 4
				c += 1
			elif r % 2 == 0:
				r = r // 2
				c += 1
			else:
				flag = 0
				break
		if flag == 0:
			print('-1')
		else:
			print(c)
	else:
		print('-1')


def ans(a, b, c):
	if a == b:
		print(c)
	if a > b:
		if a // 8 >= b and a % 8 == 0:
			c += 1
			ans(a // 8, b, c)
		elif a // 4 >= b and a % 4 == 0:
			c += 1
			ans(a // 4, b, c)
		elif a // 2 >= b and a % 2 == 0:
			c += 1
			ans(a // 2, b, c)
		else:
			print(-1)
	if a < b:
		if a * 8 <= b:
			c += 1
			ans(a * 8, b, c)
		elif a * 4 <= b:
			c += 1
			ans(a * 4, b, c)
		elif a * 2 <= b:
			c += 1
			ans(a * 2, b, c)
		else:
			print(-1)
n = int(input())
for i in range(n):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	ans(a, b, 0)


for i in range(int(input())):
	(a, b) = list(map(int, input().split()))
	if a == b:
		print(0)
	else:
		if b > a:
			ka = a
			kb = b
			a = kb
			b = ka
		co = 0
		an = 0
		while a > b:
			if a % 8 == 0 and a // 8 >= b:
				a = a // 8
				co += 1
			elif a % 4 == 0 and a // 4 >= b:
				a = a // 4
				co += 1
			elif a % 2 == 0 and a // 2 >= b:
				a = a // 2
				co += 1
			else:
				break
		if a == b:
			print(co)
		else:
			print(-1)


linp = 'list(map(int,input().split()))'
for _ in range(int(input())):
	(a, b) = eval(linp)
	if a == b:
		print(0)
		continue
	(ba, bb) = (bin(a)[2:], bin(b)[2:])
	if ba.strip('0') != bb.strip('0'):
		print(-1)
		continue
	(za, zb) = (0, 0)
	for i in range(1, len(ba) + 1):
		if ba[-i] == '1':
			break
		za += 1
	for i in range(1, len(bb) + 1):
		if bb[-i] == '1':
			break
		zb += 1
	ans = 0
	if a < b:
		zb -= za
		ans += zb // 3
		zb %= 3
		ans += zb // 2
		zb %= 2
		ans += zb
	else:
		za -= zb
		ans += za // 3
		za %= 3
		ans += za // 2
		za %= 2
		ans += za
	print(ans)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	(k1, k2) = (max(a, b), min(a, b))
	if k1 % k2 != 0:
		print(-1)
	else:
		k = k1 // k2
		c = 0
		flag = True
		while k != 1:
			flag = False
			if k % 8 == 0:
				k = k // 8
				c += 1
				flag = True
			elif k % 4 == 0:
				k //= 4
				c += 1
				flag = True
			elif k % 2 == 0:
				k //= 2
				c += 1
				flag = True
			if not flag:
				print(-1)
				break
		if flag:
			print(c)


def solve(a, b):
	if b > a:
		(a, b) = (b, a)
	i = 0
	while a >= b:
		if a == b:
			return i
		i += 1
		for _ in range(3):
			if a & 1 == 0:
				a >>= 1
				if a == b:
					return i
			else:
				return -1
	return -1
for T in range(int(input())):
	print(solve(*map(int, input().split())))


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	num = 0
	while a % 2 == 0:
		a //= 2
		num += 1
	num2 = 0
	while b % 2 == 0:
		b //= 2
		num2 += 1
	if a == b:
		dist = abs(num - num2)
		print(dist // 3 + int(dist % 3 != 0))
	else:
		print(-1)


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(t,) = I()
for _ in range(t):
	(a, b) = I()
	an = 0
	if a > b:
		(a, b) = (b, a)
	if a <= b:
		if b % a != 0:
			print(-1)
		else:
			x = b // a
			h = -1
			for i in range(60):
				if 1 << i ^ x == 0:
					h = i
					break
			if x == 2 ** h:
				print(h // 3 + bool(h % 3))
			else:
				print(-1)


for _ in range(int(input())):
	(a, b) = [int(item) for item in input().split()]
	(a, b) = (min(a, b), max(a, b))
	i = 0
	while a < b:
		a *= 2
		i += 1
	if a == b:
		print(i // 3 + i % 3 // 2 + (i % 3 - 2 * (i % 3 // 2)))
	else:
		print(-1)


import math

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b / gcd(a, b)

def bs(arr, l, r, x):
	while l <= r:
		mid = l + (r - l) // 2
		if arr[mid] == x:
			return arr[mid]
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return -1

def swap(list, pos1, pos2):
	(list[pos1], list[pos2]) = (list[pos2], list[pos1])
	return list
t = int(input())
for _ in range(t):
	(aa, bb) = map(int, input().split())
	two = 0
	a = min(aa, bb)
	b = max(bb, aa)
	if a == b:
		print(0)
		continue
	while a < b:
		a = a * 2
		two += 1
		if a > b:
			print(-1)
			break
		elif a == b:
			p1 = 0
			p1 += two // 3
			two = two % 3
			p1 += two // 2
			two = two % 2
			p1 += two // 1
			two = two % 1
			print(p1)
			break


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	else:
		(a, b) = (max(a, b), min(a, b))
		if a % b != 0:
			print(-1)
			continue
		power = a // b
		cnt = 0
		while power != 1:
			if power % 8 == 0:
				power = power // 8
				cnt += 1
			elif power % 4 == 0:
				power = power // 4
				cnt += 1
			elif power % 2 == 0:
				power = power // 2
				cnt += 1
			else:
				cnt = -1
				break
		print(cnt)


from math import floor, ceil
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	f = 0
	cnt = 0
	c = 0
	if a > b:
		while a > b:
			if a & 1:
				f = 1
				break
			a //= 2
			cnt += 1
		if not f and a == b:
			c += cnt // 3
			cnt -= cnt // 3 * 3
			c += cnt // 2
			cnt -= cnt // 2 * 2
			c += cnt
			print(c)
		else:
			print(-1)
	else:
		while a < b:
			a *= 2
			cnt += 1
		if a == b:
			c += cnt // 3
			cnt -= cnt // 3 * 3
			c += cnt // 2
			cnt -= cnt // 2 * 2
			c += cnt
			print(c)
		else:
			print(-1)


from math import log

def isPowerOf2(x):
	return x & x - 1 == 0 and x != 0

def a2b(a, b):
	if a == b:
		return 0
	if a != 0 and b == 0:
		return -1
	if a % b != 0:
		return -1
	if not isPowerOf2(a // b):
		return -1
	ans = 0
	n = int(log(a // b, 2))
	ans += n // 3
	n -= n // 3 * 3
	ans += n // 2
	n -= n // 2 * 2
	ans += n
	return ans
n = int(input())
for i in range(n):
	(a, b) = [int(x) for x in input().split()]
	print(a2b(max(a, b), min(a, b)))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	if a == b:
		print(0)
	elif b % a != 0:
		print(-1)
	else:
		q = b // a
		if q % 2 != 0:
			print(-1)
		else:
			count = 0
			while q % 2 == 0:
				count += 1
				q //= 2
			if q != 1:
				print(-1)
			else:
				ans = count // 3
				if count % 3 == 0:
					print(ans)
				else:
					print(ans + 1)


def divisibility_by_2(a, b):
	counter = 0
	n = b // a
	while n % 2 == 0:
		n = n // 2
		counter += 1
	return (n, counter)

def main_function():
	input_data = [[int(i) for i in input().split(' ')] for h in range(int(input()))]
	for i in input_data:
		(a, b) = sorted(i)
		if b % a != 0:
			print(-1)
			continue
		else:
			(n, counter) = divisibility_by_2(a, b)
			if n != 1:
				print(-1)
				continue
			else:
				eight = counter // 3
				counter -= eight * 3
				four = counter // 2
				counter -= four * 2
				print(eight + four + counter)
main_function()


import sys
import math as mt
input = sys.stdin.buffer.readline
t = int(input())
for __ in range(t):
	(a, b) = map(int, input().split())
	maxi = max(a, b)
	mini = min(a, b)
	ch = maxi // mini
	if maxi % mini == 0:
		power = int(mt.log2(maxi // mini))
		if mini * 2 ** power == maxi:
			f = power // 3
			ans = power % 3
			f += ans // 2
			ans = ans % 2
			f += ans
			print(f)
		else:
			print(-1)
	else:
		print(-1)


import math

def solve():
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	if b % a != 0:
		print(-1)
	else:
		d = b // a
		cnt = 0
		while d % 2 == 0:
			d //= 2
			cnt += 1
		if d > 1:
			print(-1)
		else:
			print(math.ceil(cnt / 3))
t = int(input())
for _ in range(t):
	solve()


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	i = 0
	if b < a:
		while a > b:
			if a % 2 != 0:
				break
			else:
				a //= 2
				i += 1
	else:
		while a < b:
			a *= 2
			i += 1
	if a != b:
		print(-1)
	else:
		out = i // 3
		i %= 3
		out += i // 2
		i %= 2
		out += i
		print(out)


t = int(input())
for i in range(t):
	(A, B) = map(int, input().split())
	a = bin(A)
	b = bin(B)
	a = a[2:len(a)]
	b = b[2:len(b)]
	if A == B:
		print(0)
	elif A < B:
		if (a in b) & (a.count('1') == b.count('1')):
			a = a[::-1]
			b = b[::-1]
			temp = b.find(a)
			if temp % 3 == 0:
				print(temp // 3)
			else:
				print(int(temp / 3) + 1)
		else:
			print(-1)
	elif B < A:
		if (b in a) & (a.count('1') == b.count('1')):
			a = a[::-1]
			b = b[::-1]
			temp = a.find(b)
			if temp % 3 == 0:
				print(temp // 3)
			else:
				print(int(temp / 3) + 1)
		else:
			print(-1)


for _ in range(int(input())):
	(a, b) = sorted(map(int, input().split()))
	ba = b // a
	if ba * a != b:
		print(-1)
		continue
	if 2 ** (ba.bit_length() - 1) == ba:
		print((ba.bit_length() - 1 + 2) // 3)
		continue
	print(-1)


t = int(input())
for q in range(t):
	(a, b) = map(int, input().split())
	(a, b) = (bin(min(a, b))[2:], bin(max(a, b))[2:])
	if a not in b or b.count('1') > a.count('1'):
		print(-1)
	else:
		ans = len(b) - len(a)
		if ans % 3 == 0:
			print(ans // 3)
		else:
			print(ans // 3 + 1)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	c = 0
	if a > b:
		while a > b and a & 1 == 0:
			a >>= 1
			c += 1
	elif a < b:
		while a < b:
			a <<= 1
			c += 1
	if a != b:
		print(-1)
		continue
	print((c + 2) // 3)


t = int(input())
while t:
	t -= 1
	(a, b) = [int(i) for i in input().split()]
	if a == b:
		print(0)
	if b > a:
		if b % a != 0:
			print(-1)
		else:
			m = b // a
			if bin(m)[2:].count('1') != 1:
				print(-1)
			else:
				count = 0
				while m >= 8:
					m = m // 8
					count += 1
				while m >= 4:
					m = m // 4
					count += 1
				while m >= 2:
					m = m // 2
					count += 1
				print(count)
	if a > b:
		if a % b != 0:
			print(-1)
		else:
			m = a // b
			if bin(m)[2:].count('1') != 1:
				print(-1)
			else:
				count = 0
				while m >= 8:
					m = m // 8
					count += 1
				while m >= 4:
					m = m // 4
					count += 1
				while m >= 2:
					m = m // 2
					count += 1
				print(count)


from collections import deque
test_cases = int(input())

def solve():
	(a, b) = input().split(' ')
	a = int(a)
	b = int(b)
	if a == b:
		return '0'
	if b > a:
		(a, b) = (b, a)
	if a % 2 != 0 and b % 2 != 0 or a % b != 0:
		return '-1'

	def bfs():
		queue = deque()
		queue.append(a)
		visited = set()
		moves = 0
		while len(queue) > 0:
			size = len(queue)
			for _ in range(size):
				value = queue.popleft()
				if value == b:
					return moves
				if value % 8 == 0:
					r = value // 8
					if r not in visited:
						visited.add(r)
						queue.append(r)
				if value % 4 == 0:
					r = value // 4
					if r not in visited:
						visited.add(r)
						queue.append(r)
				if value % 2 == 0:
					r = value // 2
					if r not in visited:
						visited.add(r)
						queue.append(r)
			moves += 1
		return -1
	return bfs()
for _ in range(test_cases):
	print(solve())


z = input
mod = 10 ** 9 + 7
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)
for _ in range(int(z())):
	(a, b) = sorted(map(int, z().split()))
	i = 0
	while True:
		(a, b) = sorted([a, b])
		if a == b:
			print(i)
			break
		if b % a != 0:
			print(-1)
			break
		t = b - a
		l = [8, 4, 2]
		for j in range(3):
			if a * l[j] <= b:
				i += 1
				a = a * l[j]
				break


def min_operations(a, b):
	oper = 0
	while a <= b:
		if a * 8 <= b:
			a *= 8
			oper += 1
			continue
		if a * 4 <= b:
			a *= 4
			oper += 1
			continue
		if a * 2 <= b:
			a *= 2
			oper += 1
			continue
		else:
			if a == b:
				return oper
			return -1
	while a >= b:
		if a // 8 >= b and a % 8 == 0:
			a //= 8
			oper += 1
			continue
		if a // 4 >= b and a % 4 == 0:
			a //= 4
			oper += 1
			continue
		if a // 2 >= b and a % 2 == 0:
			a //= 2
			oper += 1
			continue
		else:
			if a == b:
				return oper
			return -1
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	print(min_operations(a, b))


t = int(input())
p = []
for i in range(t):
	z = list(map(int, input().split()))
	a = z[0]
	b = z[1]
	if a == b:
		p.append(0)
	elif a > b:
		if a % b != 0:
			p.append(-1)
		else:
			c = a // b
			if c % 2 != 0:
				p.append(-1)
			else:
				k = 0
				while c % 8 == 0:
					c = c // 8
					k = k + 1
				l = 0
				while c % 4 == 0:
					c = c // 4
					l = l + 1
				m = 0
				while c % 2 == 0:
					c = c // 2
					m = m + 1
				if c != 1:
					p.append(-1)
				else:
					p.append(k + l + m)
	elif b % a != 0:
		p.append(-1)
	else:
		c = b // a
		if c % 2 != 0:
			p.append(-1)
		else:
			k = 0
			while c % 8 == 0:
				c = c // 8
				k = k + 1
			l = 0
			while c % 4 == 0:
				c = c // 4
				l = l + 1
			m = 0
			while c % 2 == 0:
				c = c // 2
				m = m + 1
			if c != 1:
				p.append(-1)
			else:
				p.append(k + l + m)
for i in range(len(p)):
	print(p[i])


t = int(input())
while t:
	(p, q) = map(int, input().split())
	A = min(p, q)
	B = max(p, q)
	a = bin(A)
	b = bin(B)
	a = a[2:]
	b = b[2:]
	c = len(b) - len(a)
	if len(b) > len(a):
		a = a + (len(b) - len(a)) * '0'
	f = 1
	for i in range(0, len(b), 1):
		if a[i] != b[i]:
			f = 0
	if f == 0:
		print(-1)
	else:
		cnt = 0
		while c > 0:
			if c >= 3:
				cnt += 1
				c -= 3
			elif c == 2:
				cnt += 1
				c -= 2
			elif c == 1:
				cnt += 1
				c -= 1
		print(cnt)
	t -= 1


import sys
input = sys.stdin.buffer.readline
t = int(input())
for _ in range(t):
	(a, b) = [int(x) for x in input().split()]
	(u, v) = (max([a, b]), min([a, b]))
	cnt = 0
	while v < u:
		v *= 2
		cnt += 1
	if v == u:
		print((cnt + 2) // 3)
	else:
		print(-1)


import sys
for _ in range(int(sys.stdin.readline().rstrip())):
	(a, b) = list(map(int, sys.stdin.readline().rstrip().split()))
	(a, b) = (max(a, b), min(a, b))
	re = 0
	c = 0
	while True:
		if a == b:
			break
		if b > a:
			re = -1
			break
		b *= 2
		c += 1
	if re != -1:
		re += int(c / 3)
		c = c % 3
		if c > 0:
			re += 1
	print(re)


import math
a = int(input())
for i in range(a):
	(c, d) = map(int, input().split())
	(c, d) = (min(c, d), max(c, d))
	num = 0
	while c != d:
		if math.floor(d / c) == d // c and d // c % 8 == 0:
			c *= 8
			num += 1
		elif math.floor(d / c) == d // c and d // c % 4 == 0:
			c *= 4
			num += 1
		elif math.floor(d / c) == d // c and d // c % 2 == 0:
			c *= 2
			num += 1
		else:
			num = -1
			break
	print(num)


for t in range(int(input())):
	(A, B) = map(int, input().split())
	if A < B:
		(A, B) = (B, A)
	z = 0
	while A > B and A % 2 == 0:
		A >>= 1
		z += 1
	if A == B:
		c = 0
		c += z // 3
		z -= z // 3 * 3
		c += z // 2
		z -= z // 2 * 2
		c += z // 1
		z -= z // 1 * 1
		print(c)
	else:
		print(-1)


def getR(n):
	while n % 2 == 0:
		n = n // 2
	return n

def findMoves(a, b):
	r_a = getR(a)
	if getR(b) != r_a:
		return -1
	res = 0
	b = b // a
	while b % 8 == 0:
		b = b // 8
		res += 1
	if b > 1:
		res += 1
	return res
n = int(input())
for _ in range(n):
	(a, b) = map(int, input().split())
	res = 0
	if a < b:
		res = findMoves(a, b)
	elif b < a:
		res = findMoves(b, a)
	print(res)


for u in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	else:
		if a > b:
			(a, b) = (b, a)
		ans = 0
		f = False
		while True:
			if b % 8 == 0 and b // 8 == a:
				f = True
				ans += 1
				break
			elif b % 4 == 0 and b // 4 == a:
				f = True
				ans += 1
				break
			elif b % 2 == 0 and b // 2 == a:
				f = True
				ans += 1
				break
			if f == True:
				break
			elif b % 8 == 0:
				b = b // 8
				ans += 1
			elif b % 4 == 0:
				b = b // 4
				ans += 1
			elif b % 2 == 0:
				b = b // 2
				ans += 1
			else:
				break
		if f == True:
			print(ans)
		else:
			print(-1)


def primeFactors(n):
	ans = 0
	while n % 2 == 0:
		n //= 2
		ans += 1
	return (ans, n)
import math
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	(ans_A, a) = primeFactors(a)
	(ans_B, b) = primeFactors(b)
	if a == b:
		dif = abs(ans_A - ans_B)
		ans = dif // 3
		dif %= 3
		ans += dif // 2
		dif %= 2
		ans += dif
		print(ans)
	else:
		print(-1)


ll = lambda : list(map(int, input().split()))
s = lambda : input()
v = lambda : map(int, input().split())
ii = lambda : int(input())
import math
from collections import Counter
for _ in range(ii()):
	(x, y) = v()
	a = max(y, x)
	b = min(x, y)
	if a % b != 0:
		print(-1)
	else:
		x = a // b
		a = 0
		while x != 1:
			if x % 8 == 0:
				x = x // 8
			elif x % 4 == 0:
				x = x // 4
			elif x % 2 == 0:
				x = x // 2
			else:
				a = -1
				break
			a += 1
		print(a)


import sys
input = sys.stdin.readline
t = int(input())
import math
for t1 in range(t):
	(a, b) = list(map(int, input().split(' ')))
	a1 = min(a, b)
	a2 = max(a, b)
	z = a2 / a1
	z = math.log(z, 2)
	extra = 1 << int(z)
	if extra * a1 == a2:
		print(math.ceil(z / 3))
	else:
		print(-1)


for t in range(int(input())):
	(a, b) = map(int, input().split())
	m = max(a, b)
	n = min(a, b)
	if a == b:
		print(0)
	elif m % n == 0:
		count = 0
		while n < m:
			count += 1
			if m // n >= 8:
				n = n * 8
			elif m // n >= 4:
				n = n * 4
			else:
				n = n * 2
		if m != n:
			print(-1)
		else:
			print(count)
	else:
		print(-1)


import os
import sys
from io import BytesIO, IOBase

def solution(a, b):
	if a == b:
		write(0)
		return
	res = 0
	if a > b:
		(a, b) = (b, a)
	while a * 8 <= b:
		a *= 8
		res += 1
	if a == b:
		write(res)
		return
	while a * 4 <= b:
		a *= 4
		res += 1
	if a == b:
		write(res)
		return
	while a * 2 <= b:
		a *= 2
		res += 1
	if a == b:
		write(res)
		return
	write(-1)

def main():
	for _ in range(r_int()):
		(a, b) = r_array()
		solution(a, b)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def write(*args, end='\n'):
	for x in args[:-1]:
		sys.stdout.write(str(x) + ' ')
	sys.stdout.write(str(args[-1]))
	sys.stdout.write(end)

def r_array():
	return [int(x) for x in input().split()]

def r_int():
	return int(input())
main()


MOD = 10 ** 9 + 7
INT_MAX = 10 ** 20 + 7

def INPUT():
	return list((int(i) for i in input().split()))

def LIST_1D_ARRAY(n):
	return [0 for _ in range(n)]

def LIST_2D_ARRAY(m, n):
	return [[0 for _ in range(n)] for _ in range(m)]

def power(a, x):
	res = 1
	while x > 0:
		if x & 1:
			res = res * a % MOD
		a = a * a % MOD
		x //= 2
	return res % MOD

def NCR_MOD(n, r):
	num = 1
	for i in range(n, n - r, -1):
		num = num * i % MOD
	for j in range(1, r + 1):
		num = num * power(j, MOD - 2) % MOD
	return num
import math
from collections import deque

def P(x):
	a = 1
	count = 0
	while a < x:
		a *= 2
		count += 1
	if a == x:
		return count
	return -1

def calc(a, b):
	if b >= a:
		if b % a != 0:
			return -1
		x = P(b // a)
		if x == -1:
			return -1
		if x % 1 != 0:
			return -1
		if x % 3 == 0:
			return x // 3
		else:
			return x // 3 + 1
	if a % b != 0:
		return -1
	x = P(a // b)
	if x == -1:
		return -1
	if x % 1 != 0:
		return -1
	if x % 3 == 0:
		return x // 3
	else:
		return x // 3 + 1
for i in range(int(input())):
	(a, b) = INPUT()
	print(int(calc(a, b)))


T = int(input())
for t_itr in range(T):
	(A, B) = map(int, input().rstrip().split())
	a_bin = bin(A)
	b_bin = bin(B)
	if len(a_bin) > len(b_bin):
		(b_bin, a_bin) = (a_bin, b_bin)
	can_replace = True
	for i in range(len(a_bin)):
		if b_bin[i] != a_bin[i]:
			can_replace = False
			break
	for i in range(len(a_bin), len(b_bin)):
		if b_bin[i] != '0':
			can_replace = False
			break
	if can_replace:
		(r, m) = divmod(len(b_bin) - len(a_bin), 3)
		if m > 0:
			r += 1
		print(r)
	else:
		print(-1)


t = input()
for _ in range(int(t)):
	(a, b) = input().split(' ')
	a = int(a)
	b = int(b)
	if a == b:
		print(0)
		continue
	if a > b:
		if a % b != 0:
			print(-1)
			continue
		y = a // b
	else:
		if b % a != 0:
			print(-1)
			continue
		y = b // a
	c = 0
	while y % 8 == 0:
		y //= 8
		c += 1
	while y % 4 == 0:
		y //= 4
		c += 1
	while y % 2 == 0:
		y //= 2
		c += 1
	if y != 1:
		print(-1)
	else:
		print(c)


import sys
import os
import io
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
import math

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def si():
	return input()

def prefix_sum(arr):
	r = [0] * (len(arr) + 1)
	for (i, el) in enumerate(arr):
		r[i + 1] = r[i] + el
	return r

def divideCeil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def ii():
	return int(input())

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def li():
	return list(map(int, input().split()))
t = int(input())
for _ in range(t):
	(a, b) = li()
	if a > b:
		(a, b) = (b, a)
	cnt = 0
	while a < b:
		a *= 2
		cnt += 1
	if a == b:
		ans = 0
		ans += cnt // 3
		cnt %= 3
		ans += cnt // 2
		cnt %= 2
		ans += cnt
		print(ans)
	else:
		print(-1)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	elif a > b:
		count = 0
		while a > b:
			if not a & 1:
				a = a // 2
				count += 1
			else:
				break
		if a == b:
			p = count // 3
			count = count % 3
			p += count // 2
			count = count % 2
			print(p + count)
		else:
			print(-1)
	else:
		count = 0
		while a < b:
			a = a * 2
			count += 1
		if a == b:
			p = count // 3
			count = count % 3
			p += count // 2
			count = count % 2
			print(p + count)
		else:
			print(-1)


from math import inf as inf
from math import *
from collections import *
import sys
input = sys.stdin.readline
t = int(input())
while t:
	t -= 1
	(a, b) = map(int, input().split())
	a1 = bin(a)[2:]
	b1 = bin(b)[2:]
	if a == b:
		print(0)
		continue
	re = -1
	if a > b:
		s = 0
		flag = 0
		while a > b:
			if a % 8 == 0 and a // 8 >= b:
				s += 1
				a = a // 8
			elif a % 4 == 0 and a // 4 >= b:
				s += 1
				a = a // 4
			elif a % 2 == 0 and a // 2 >= b:
				s += 1
				a = a // 2
			else:
				break
			if a == b:
				flag = 1
				break
		if s > 0 and flag:
			print(s)
		else:
			print(-1)
	else:
		s = 0
		flag = 0
		while a < b:
			if 8 * a <= b:
				s += 1
				a = a * 8
			elif 4 * a <= b:
				s += 1
				a = a * 4
			elif 2 * a <= b:
				s += 1
				a = a * 2
			else:
				break
			if a == b:
				flag = 1
				break
		if s == 0 or flag == 0:
			print(-1)
		else:
			print(s)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	n1 = str(bin(min(m, n)))[::-1].index('1')
	m1 = str(bin(max(m, n)))[::-1].index('1')
	diff = m1 - n1
	if m1 - n1 < 0:
		print(-1)
	else:
		x = min(n, m) << diff
		if x == max(n, m):
			print(diff // 3 + (0, 1)[diff % 3 > 0])
		else:
			print(-1)


import math
t = int(input())
while t:
	t -= 1
	(n, m) = map(int, input().split())
	c = 0
	if n > m:
		(n, m) = (m, n)
	while n < m:
		n *= 2
		c += 1
	if n == m:
		print(math.ceil(c / 3))
	else:
		print(-1)


def isPossible(x):
	count = 0
	while x > 1:
		if x % 2 != 0:
			return -1
		x = x // 2
		count += 1
	return count
T = int(input())
for _ in range(T):
	(x, y) = map(int, input().split())
	(h, l) = (0, 0)
	if x > y:
		h = x
		l = y
	else:
		h = y
		l = x
	if h % l == 0:
		x = isPossible(h // l)
		if x != -1:
			if x % 3 == 0:
				print(x // 3)
			else:
				print(x // 3 + 1)
		else:
			print('-1')
	else:
		print('-1')


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	else:
		l = [2, 4, 8]
		if a > b and a % b != 0:
			print(-1)
		elif a < b and b % a != 0:
			print(-1)
		else:
			c = 1
			if a > b:
				n = a // b
			else:
				n = b // a
			while n not in l:
				if n % 2 == 0:
					if n % 4 == 0:
						if n % 8 == 0:
							n = n // 8
							c += 1
						else:
							n = n // 4
							c += 1
					else:
						n = n // 2
						c += 1
				else:
					c = -1
					break
			print(c)


import sys
input = sys.stdin.readline
import heapq
import copy
import math
import decimal

class Node:

	def _init_(self, val):
		self.data = val
		self.left = None
		self.right = None

class fen_tree:

	def __init__(self, list):
		self.array = [0] + list
		for idx in range(1, len(self.array)):
			idx2 = idx + (idx & -idx)
			if idx2 < len(self.array):
				self.array[idx2] += self.array[idx]

	def prefix_query(self, idx):
		result = 0
		while idx:
			result += self.array[idx]
			idx -= idx & -idx
		return result

	def prints(self):
		print(self.array)
		return

	def range_query(self, from_idx, to_idx):
		return self.prefix_query(to_idx) - self.prefix_query(from_idx - 1)

	def update(self, idx, add):
		while idx < len(self.array):
			self.array[idx] += add
			idx += idx & -idx

def pre_sum(arr):
	p = [0]
	for i in arr:
		p.append(p[-1] + i)
	p.pop(0)
	return p

def pre_back(arr):
	p = [0]
	for i in arr:
		p.append(p[-1] + i)
	p.pop(0)
	return p

def bin_search(arr, l, r, val):
	if arr[r] <= val:
		return r + 1
	if r - l < 2:
		if arr[l] > val:
			return l
		else:
			return r
	mid = int((l + r) / 2)
	if arr[mid] <= val:
		return bin_search(arr, mid, r, val)
	else:
		return bin_search(arr, l, mid, val)

def search_leftmost(arr, val):

	def helper(arr, l, r, val):
		print(l, r)
		if arr[l] == val:
			return l
		if r - l <= 1:
			if arr[r] == val:
				return r
			else:
				print('not found')
				return
		mid = int((r + l) / 2)
		if arr[mid] >= val:
			return helper(arr, l, mid, val)
		else:
			return helper(arr, mid, r, val)
	return helper(arr, 0, len(arr) - 1, val)

def search_rightmost(arr, val):

	def helper(arr, l, r, val):
		print(l, r)
		if arr[r] == val:
			return r
		if r - l <= 1:
			if arr[l] == val:
				return r
			else:
				print('not found')
				return
		mid = int((r + l) / 2)
		if arr[mid] > val:
			return helper(arr, l, mid, val)
		else:
			return helper(arr, mid, r, val)
	return helper(arr, 0, len(arr) - 1, val)

def preorder_postorder(root, paths, parent, left, level):
	l = 0
	queue = [root]
	while queue != []:
		node = queue[-1]
		flag = 0
		for i in paths[node]:
			if i != parent[node] and level[i] == sys.maxsize:
				parent[i] = node
				level[i] = level[node] + 1
				flag = 1
				queue.append(i)
		if flag == 0:
			left[parent[node]] += 1 + left[node]
			queue.pop()
	return [parent, left, level]

def nCr(n, r, p):
	if r == 0:
		return 1
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def insr2():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())

def make_tree(n):
	root = 1
	paths2 = [[] for i in range(n + 1)]
	parent = [0 for i in range(n + 1)]
	for i in range(n - 1):
		[p, child] = inlt()
		paths2[p].append(child)
		paths2[child].append(p)
	path = [[] for i in range(n + 1)]
	root = 1
	queue = [root]
	parent[1] = -1
	while queue != []:
		curr = queue.pop(0)
		for i in paths2[curr]:
			if parent[i] == 0:
				parent[i] = curr
				queue.append(i)
				path[curr].append(i)
	parent[1] = 0
	return [path, parent]

def pr_list(a):
	print(*a, sep=' ')

def main():
	tests = inp()
	mod = 1000000007
	limit = 10 ** 18
	ans = 0
	for test in range(tests):
		[a, b] = inlt()
		a_2 = 0
		while a % 2 == 0:
			a_2 += 1
			a = a // 2
		b_2 = 0
		while b % 2 == 0:
			b_2 += 1
			b = b // 2
		if a != b:
			print(-1)
		else:
			opr = abs(a_2 - b_2)
			if opr % 3 == 0:
				print(opr // 3)
			elif opr % 3 == 1:
				print(opr // 3 + 1)
			else:
				print(opr // 3 + 1)
main()


for i in range(int(input())):
	sum = 0
	(p, q) = map(int, input().split())
	if p == q:
		print(0)
	else:
		if p > q:
			a = p
			b = q
		else:
			a = q
			b = p
		if a % b != 0:
			print(-1)
		else:
			while b < a:
				if b * 8 <= a:
					b *= 8
				elif b * 4 <= a:
					b *= 4
				else:
					b *= 2
				sum += 1
			if a == b:
				print(sum)
			else:
				print(-1)


from collections import Counter, defaultdict
BS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def to_base(s, b):
	res = ''
	while s:
		res += BS[s % b]
		s //= b
	return res[::-1] or '0'
alpha = 'abcdefghijklmnopqrstuvwxyz'
from math import floor, ceil
t = int(input())
for i in range(t):
	(a, b) = sorted(list(map(int, input().split())))
	if a == b:
		print(0)
	else:
		got = None
		c = 0
		while a < b:
			a *= 2
			c += 1
			if a == b:
				got = c
				break
		if not got:
			print(-1)
		else:
			print(c // 3 + (1 if c % 3 != 0 else 0))


for _ in range(int(input())):
	(a, b) = list(map(int, input().split()))
	if a == b:
		print(0)
		continue
	first = bin(a)[2:]
	second = bin(b)[2:]
	firstRemoved = first.lstrip('0')
	x = first.strip('0')
	secondRemoved = second.lstrip('0')
	y = second.strip('0')
	if x == y:
		countFirst = firstRemoved.replace(x, '')
		countSecond = secondRemoved.replace(x, '')
		differnce = len(countFirst) - len(countSecond) if countFirst > countSecond else len(countSecond) - len(countFirst)
		count = 0
		count += differnce // 3
		differnce %= 3
		count += differnce // 2
		differnce %= 2
		count += differnce
		print(count)
	else:
		print(-1)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if max(a, b) % min(a, b) != 0:
		print(-1)
	elif a == b:
		print(0)
	else:
		c = max(a, b) // min(a, b)
		ans = 0
		while c % 8 == 0:
			c //= 8
			ans += 1
		while c % 4 == 0:
			c //= 4
			ans += 1
		while c % 2 == 0:
			c //= 2
			ans += 1
		if c == 1:
			print(ans)
		else:
			print(-1)


t = int(input())
while t:
	t -= 1
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	elif a > b:
		c = 0
		flag = 0
		while a > b:
			if a % 2 == 1:
				flag = 1
				break
			a = a // 2
			c += 1
		if a == b and flag == 0:
			ans = c // 3
			c = c % 3
			ans += c // 2
			c = c % 2
			ans += c
			print(ans)
		else:
			print(-1)
	else:
		c = 0
		flag = 0
		while b > a:
			if b % 2 == 1:
				flag = 1
				break
			a = a * 2
			c += 1
		if a == b and flag == 0:
			ans = c // 3
			c = c % 3
			ans += c // 2
			c = c % 2
			ans += c
			print(ans)
		else:
			print(-1)


n = int(input())
a = [0] * n
b = [0] * n
c = [0] * n
d = 0
e = 0
k = 0
for i in range(0, n):
	(b[i], a[i]) = map(int, input().split())
	d = max(a[i], b[i])
	e = a[i] + b[i] - d
	if d == e:
		c[i] = 0
	elif d != e and d % 2 == 1 and (e % 2 == 1):
		c[i] = -1
	elif d % 2 == 1:
		c[i] = -1
	elif d % e == 0 and (d // e == 2 or d // e == 4 or d // e == 8):
		c[i] = 1
	elif e % 2 == 1 and d % 2 == 0 or (e % 2 == 0 and d % 2 == 0):
		while e < d:
			if e * 8 > d:
				if e * 4 > d:
					if e * 2 > d:
						k = -1
						e *= 2
					else:
						k += 1
						e *= 2
				else:
					k += 1
					e *= 4
			else:
				k += 1
				e *= 8
		c[i] = k
		k = 0
for i in range(0, n):
	print(c[i])


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if b > a:
		temp = b
		b = a
		a = temp
	ans = True
	sum = 0
	while b < a:
		if 8 * b <= a:
			b *= 8
			sum += 1
		elif 4 * b <= a:
			b *= 4
			sum += 1
		elif 2 * b <= a:
			b *= 2
			sum += 1
		else:
			ans = False
			break
	if not ans:
		print(-1)
	else:
		print(sum)


import sys
from collections import defaultdict as dd
from collections import deque
from fractions import Fraction as f

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
from math import *
import copy
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')

def li():
	return [int(x) for x in input().split()]

def fi():
	return int(input())

def si():
	return list(input().rstrip())

def mi():
	return map(int, input().split())

def gh():
	sys.stdout.flush()

def bo(i):
	return ord(i) - ord('a')
from copy import *
from bisect import *
t = fi()
while t > 0:
	t -= 1
	(a, b) = mi()
	if b > a:
		(a, b) = (b, a)
	if a % b != 0:
		print(-1)
	else:
		p = a // b
		c = 0
		while p % 8 == 0:
			p //= 8
			c += 1
		while p % 4 == 0:
			p //= 4
			c += 1
		while p % 2 == 0:
			p //= 2
			c += 1
		print(c if p == 1 else -1)


t = int(input())
for tcases in range(t):
	(a, b) = map(int, input().split())
	count = 0
	acount = 0
	bcount = 0
	if a > b:
		(maxi, mini) = (a, b)
	else:
		(maxi, mini) = (b, a)
	while maxi > mini:
		mini = mini * 2
		count += 1
	if maxi == mini:
		result = count // 3
		count = count % 3
		result = result + count // 2
		count = count % 2
		result = result + count // 1
		print(result)
	else:
		print(-1)


def powers(elem):
	op = 0
	factor = elem
	pot = 8
	while factor != 1:
		while factor < pot:
			pot = pot / 2
		factor = factor / pot
		op = op + 1
	return op

def operations(a, b):
	if a == b:
		return 0
	if a == 0 or b == 0:
		(zero, quoc) = (a, b if a == 0 else b, a)
		if quoc & quoc - 1 != 0 or quoc == 1:
			return -1
		else:
			return powers(quoc)
	(quoc, rest) = divmod(a, b) if a > b else divmod(b, a)
	if rest != 0:
		return -1
	if quoc & quoc - 1 != 0:
		return -1
	return powers(quoc)

def main():
	t = int(input().rstrip())
	while t:
		(a, b) = map(int, input().rstrip().split())
		op = operations(a, b)
		print(op)
		t = t - 1
main()


def read_list():
	return list(map(int, input().split(' ')))

def print_list(l):
	print(' '.join(map(str, l)))
import math

def gcd(m, n):
	while n:
		(m, n) = (n, m % n)
	return m
N = int(input())
for _ in range(N):
	(a, b) = read_list()
	if a % b != 0 and b % a != 0:
		print(-1)
	else:
		tmp = gcd(a, b)
		r = max(a // tmp, b // tmp)
		count = 0
		while r:
			if r & 1:
				break
			r >>= 1
			count += 1
		if r > 1:
			print(-1)
		else:
			print(math.ceil(count / 3))


t = int(input())
for i in range(t):
	(m, n) = map(int, input().split())
	x = max(m, n)
	y = min(m, n)
	c = 0
	f = -1
	if m == n:
		f = 0
	while x > y:
		f = 0
		if y * 8 <= x:
			y *= 8
		elif y * 4 <= x:
			y *= 4
		else:
			y *= 2
		c += 1
	if f != -1 and x == y:
		print(c)
	else:
		print(-1)


def f(a, b):
	if a < b:
		(a, b) = (b, a)
	ans = 0
	if a == b:
		return 0
	while b < a:
		if a == 2 * b:
			b = a
			return ans + 1
		if a == 4 * b:
			b = a
			return ans + 1
		if a == 8 * b:
			b = a
			return ans + 1
		b = 8 * b
		ans += 1
		if b > a:
			return -1
t = int(input())
for i in range(t):
	[a, b] = input().split(' ')
	print(f(int(a), int(b)))


import math
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	x = max(a, b)
	y = min(a, b)
	if x % y == 0:
		x = x // y
		if x and (not x & x - 1):
			x = int(math.log(x) / math.log(2))
			c = 0
			c = c + x // 3
			x = x % 3
			c = c + x // 2
			x = x % 2
			c = c + x
			print(c)
		else:
			print(-1)
	else:
		print(-1)


def main():
	import sys
	sys.setrecursionlimit(10 ** 6)
	input = sys.stdin.readline
	T = int(input())
	for t in range(T):
		(a, b) = [int(x) for x in input().strip().split()]
		ans = 0
		if a == b:
			print(ans)
			continue
		if a > b:
			while a > b and a % 2 != 1:
				a //= 2
				ans += 1
			if a != b:
				print(-1)
			else:
				print(ans // 3 + (ans % 3 > 0))
		else:
			while a < b:
				a *= 2
				ans += 1
			if a != b:
				print(-1)
			else:
				print(ans // 3 + (ans % 3 > 0))
main()


O = print
P = input
import math
t = int(P())
for i in '|' * t:
	(a, b) = map(int, P().split())
	Z = a
	Y = b
	if b > a:
		Z = b
		Y = a
	if Z == Y:
		O(0)
	elif Z % Y != 0:
		O(-1)
	else:
		V = 0
		U = Z // Y
		T = 0
		while U != 1:
			T += 1
			if U % 2 == 0:
				U = U // 2
			else:
				V = 1
				O(-1)
				break
		if V == 1:
			continue
		elif T % 3 == 0:
			O(T // 3)
		else:
			O(T // 3 + 1)


a = int(input())
for step in range(a):
	inp1 = [int(x) for x in input().split(' ')]
	a1 = int(inp1[0])
	b1 = int(inp1[1])
	a = max(a1, b1)
	b = min(a1, b1)
	counter = 0
	while True:
		if b == a:
			eight = counter // 3
			four = counter % 3 // 2
			two = counter % 3 % 2
			counter = eight + four + two
			print(counter)
			break
		elif b < a:
			b = b * 2
			counter += 1
		else:
			print(-1)
			break


while True:
	try:
		n = int(input())
		for i in range(n):
			(x, y) = map(int, input().split())
			a = max(x, y)
			b = min(x, y)
			if a == b:
				print(0)
			elif a % 2 and b % 2:
				print(-1)
			else:
				cnt = 0
				while b * 8 <= a:
					b = b * 8
					cnt = cnt + 1
				while b * 4 <= a:
					b = b * 4
					cnt = cnt + 1
				while b * 2 <= a:
					b = b * 2
					cnt = cnt + 1
				if b == a:
					print(cnt)
				else:
					print(-1)
	except:
		break


import math
t = int(input())
for x in range(t):
	[a, b] = list(map(int, input().split()))
	if a == b:
		print(0)
		continue
	if b > a:
		temp = 0
		temp_a = a
		while a <= b:
			if a * 2 <= b:
				temp += 1
				a = a * 2
			else:
				break
		if temp_a * 2 ** temp != b:
			print(-1)
			continue
		if temp % 3 == 0:
			print(temp // 3)
		else:
			print(temp // 3 + 1)
	else:
		temp = 0
		temp_b = b
		while b <= a:
			if b * 2 <= a:
				temp += 1
				b = b * 2
			else:
				break
		if temp_b * 2 ** temp != a:
			print(-1)
			continue
		if temp % 3 == 0:
			print(temp // 3)
		else:
			print(temp // 3 + 1)


def mul(now, tar):
	steps = 0
	while now <= tar:
		if now == tar:
			return steps
		if now * 8 <= tar:
			now *= 8
			steps += 1
			continue
		if now * 4 <= tar:
			now *= 4
			steps += 1
			continue
		if now * 2 <= tar:
			now *= 2
			steps += 1
			continue
		return -1
	return -1

def dup(now, tar):
	steps = 0
	while now >= tar:
		if now == tar:
			return steps
		if now % 8 == 0 and now // 8 >= tar:
			now //= 8
			steps += 1
			continue
		if now % 4 == 0 and now // 4 >= tar:
			now //= 4
			steps += 1
			continue
		if now % 2 == 0 and now // 2 >= tar:
			now //= 2
			steps += 1
			continue
		return -1
	return -1

def main():
	t = int(input())
	for i in range(t):
		p = input().split()
		now = int(p[0])
		tar = int(p[1])
		if now > tar:
			if now % tar != 0:
				print(-1)
				continue
			print(dup(now, tar))
		else:
			if tar % now != 0:
				print(-1)
				continue
			print(mul(now, tar))
main()


t = int(input())
while t:
	(a, b) = map(int, input().split())
	if a > b:
		k = a
		a = b
		b = k
	cnt = 0
	while a < b:
		a = a * 2
		cnt += 1
	if a != b:
		print(-1)
	else:
		print(cnt // 3 + min(cnt % 3, 1))
	t = t - 1


import sys
ints = (int(x) for x in sys.stdin.read().split())
sys.setrecursionlimit(3000)

def main():
	ntc = next(ints)
	for tc in range(1, ntc + 1):
		(a, b) = (next(ints) for i in range(2))
		c = min(a, b)
		ans = 0
		while c < max(a, b):
			c *= 2
			ans += 1
		if c > max(a, b):
			ans = -1
		else:
			(ans1, r) = divmod(ans, 3)
			(ans2, r) = divmod(r, 2)
			ans = ans1 + ans2 + r
		print(ans)
	return
main()


for p in range(int(input())):
	(a, b) = list(map(int, input().split()))
	(h, k) = (min(a, b), max(a, b))
	if h == k:
		print(0)
	elif k % h != 0:
		print(-1)
	else:
		(m, s) = (k // h, 0)
		while m > 1:
			if m % 8 == 0:
				s += 1
				m = m // 8
			elif m % 4 == 0:
				s += 1
				m = m // 4
			elif m % 2 == 0:
				s += 1
				m = m // 2
			else:
				s = -1
				break
		print(s)


from sys import stdin
from math import log2, ceil
N = int(stdin.readline())

def get(x):
	while x % 2 == 0:
		x = x // 2
	return x
for _ in range(N):
	(a, b) = map(int, stdin.readline().split())
	ra = get(a)
	rb = get(b)
	if ra != rb:
		print(-1)
	else:
		exa = log2(a // ra)
		exb = log2(b // rb)
		print(ceil(abs(exa - exb) / 3))


import math
for test in range(int(input())):
	(n, x) = map(int, input().split())
	(n, x) = (min(n, x), max(n, x))
	an = 0
	while n < x:
		n *= 2
		an += 1
	if n != x:
		print(-1)
	else:
		print(math.ceil(an / 3))


import math
we = int(input())
for erw in range(we):
	(n, x) = list(map(int, input().split(' ')))
	s = max(n, x)
	e = min(n, x)
	if s == e:
		print('0')
		continue
	s = bin(s).replace('0b', '')
	e = bin(e).replace('0b', '')
	s = list(s)
	e = list(e)
	flag = 0
	for i in range(len(e)):
		if e[i] != s[i]:
			flag = 1
			break
	if flag == 1:
		print('-1')
	else:
		s = s[len(e):]
		s = ''.join(s)
		if '1' in s:
			print('-1')
		else:
			ans = len(s)
			if ans % 3 == 0:
				ans = ans // 3
			else:
				ans = 1 + ans // 3
			print(ans)


def solve(a, b):
	if b > a:
		(a, b) = (b, a)
	if a % b > 0:
		return -1
	c = a // b
	if c & c - 1 > 0:
		return -1
	return (c.bit_length() + 1) // 3
for T in range(int(input())):
	print(solve(*map(int, input().split())))


def factors_two(a):
	cnt = 0
	while a % 2 == 0:
		cnt += 1
		a = a // 2
	return cnt
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	m = factors_two(a)
	n = factors_two(b)
	ans = -1
	if a == b:
		ans = 0
	else:
		t1 = a // pow(2, m)
		t2 = b // pow(2, n)
		if t1 == t2:
			k = abs(m - n)
			s1 = k // 3
			s2 = k % 3
			if s2 == 0:
				ans = s1
			else:
				ans = s1 + 1
		else:
			ans = -1
	if m == 0 and n == 0:
		if a != b:
			ans = -1
		else:
			ans = 0
	if ans == -1:
		print('-1')
	else:
		print(ans)


t = int(input())
for test in range(t):
	(a, b) = input().split()
	(a, b) = (int(a), int(b))
	a_2 = 0
	b_2 = 0
	while a % 2 == 0:
		a_2 += 1
		a = a // 2
	while b % 2 == 0:
		b_2 += 1
		b = b // 2
	if a != b:
		print(-1)
		continue
	diff = abs(a_2 - b_2)
	diff = diff / 3
	if diff > int(diff):
		diff = int(diff) + 1
	print(int(diff))


for _ in range(int(input())):
	l = list(map(int, input().split()))
	l = sorted(l)
	(a, b) = (l[-1], l[0])
	count = 0
	if a == b:
		print(0)
	else:
		while True:
			if a % 2 == 0 and a != b:
				a //= 2
				count += 1
			else:
				break
		if a == b:
			ans = count // 3
			count -= ans * 3
			if count > 0:
				print(ans + 1)
			else:
				print(ans)
		else:
			print(-1)


import math
for testcase in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
		continue
	(M, m) = (max(a, b), min(a, b))
	if M % m != 0:
		print(-1)
		continue
	d = M // m
	if str(bin(d)).split('b')[1].count('1') == 1:
		print(math.ceil(round(math.log2(d)) / 3))
	else:
		print(-1)


def nshifts(a, b):
	if a != b[:len(a)]:
		return -1
	else:
		b = b[len(a):]
		if b.count('1') > 0:
			return -1
		else:
			return len(b) // 3 if len(b) % 3 == 0 else len(b) // 3 + 1
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	ans = 0
	x = bin(a)[2:]
	y = bin(b)[2:]
	if a < b:
		ans = nshifts(x, y)
	else:
		ans = nshifts(y, x)
	print(ans)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	elif a > b and a % b != 0 or (b > a and b % a != 0):
		print(-1)
	else:
		t = a // b if a > b else b // a
		d = {2: 0, 4: 0, 8: 0}
		while t % 8 == 0:
			d[8] += 1
			t //= 8
		while t % 4 == 0:
			d[4] += 1
			t //= 4
		while t % 2 == 0:
			d[2] += 1
			t //= 2
		if t > 1:
			print(-1)
		else:
			s = 0
			for i in d:
				s += d[i]
			print(s)


from sys import stdin, stdout
from itertools import combinations
from collections import defaultdict, Counter
import math

def listIn():
	return list(map(int, stdin.readline().strip().split()))

def stringListIn():
	return [x for x in stdin.readline().split()]

def intIn():
	return int(stdin.readline())

def stringIn():
	return stdin.readline().strip()
t = intIn()
while t > 0:
	t -= 1
	(a, b) = listIn()
	if a == b:
		print(0)
	else:
		if a > b:
			(a, b) = (b, a)
		if b % a == 0:
			num = b // a
			cnt = 0
			b = num
			while b % 2 == 0:
				if b % 8 == 0:
					cnt += 1
					b //= 8
				elif b % 4 == 0:
					cnt += 1
					b //= 4
				elif b % 2 == 0:
					cnt += 1
					b //= 2
			if cnt == 0 or b != 1:
				print(-1)
			else:
				print(cnt)
		else:
			print(-1)


t = int(input())
while t > 0:
	t = t - 1
	(a, b) = map(int, input().split(' '))
	if a < b:
		(a, b) = (b, a)
	fa = 0
	fb = 0
	while a % 2 == 0:
		a = a // 2
		fa = fa + 1
	while b % 2 == 0:
		b = b // 2
		fb = fb + 1
	if a != b:
		print(-1)
	else:
		print((fa - fb) // 3 + ((fa - fb) % 3 != 0))


t = int(input())
i = 0
while i < t:
	(a, b) = map(int, input().split())
	count = 0
	r = True
	while True:
		if a == b:
			print(count)
			r = False
			break
		elif a > b:
			j = 0
			aa = True
			count = count + 1
			while j < 3 and a > b:
				if a % 2 != 0:
					aa = False
					break
				a = a // 2
				if a == b:
					print(count)
					r = False
					aa = False
					break
				j = j + 1
			if a < b:
				break
			if aa == False:
				break
		elif a < b:
			j = 0
			aa = True
			count = count + 1
			while j < 3 and a < b:
				a = a * 2
				if a == b:
					print(count)
					r = False
					aa = False
					break
				j = j + 1
			if a > b:
				break
			if aa == False:
				break
	if r == True:
		print(-1)
	i = i + 1


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if b > a:
		(a, b) = (b, a)
	boo = 1
	sum = 0
	while b < a:
		if 8 * b <= a:
			b *= 8
			sum += 1
		elif 4 * b <= a:
			b *= 4
			sum += 1
		elif 2 * b <= a:
			b *= 2
			sum += 1
		else:
			boo = 0
			break
	if not boo:
		print(-1)
	else:
		print(sum)


from bisect import bisect_left as lower_bound, bisect_right as upper_bound
from sys import stdin, stdout
from collections import defaultdict
from math import log2

def solve(arr, n):
	pass

def main():
	t = int(input())
	for _ in range(t):
		(a, b) = list(map(int, input().strip().split()))
		if a == b:
			print(0)
			continue
		if a > b:
			r = a // b
			if a % b != 0 or r & r - 1 != 0:
				print(-1)
				continue
			r = int(log2(r))
			print(r // 3 + (1 if r % 3 else 0))
		if a < b:
			r = b // a
			if b % a != 0 or r & r - 1 != 0:
				print(-1)
				continue
			r = int(log2(r))
			print(r // 3 + (1 if r % 3 else 0))
main()


test_case = int(input())
for _ in range(test_case):
	(a, b) = [int(f) for f in input().split()]
	count = 0
	if b == a:
		print('0')
	elif b > a:
		if b % a != 0:
			print('-1')
		else:
			flag = 1
			x = b // a
			j = 1
			i = 0
			while j < x:
				i += 1
				j = pow(2, i)
			if j != x:
				print('-1')
			else:
				count = i // 3
				if i % 3 == 0:
					print(count)
				else:
					i = i % 3
					count = count + i // 2
					i = i % 2
					count = count + i
					print(count)
	elif a > b:
		swap = a
		a = b
		b = swap
		if b % a != 0:
			print('-1')
		else:
			flag = 1
			x = b // a
			j = 1
			i = 0
			while j < x:
				i += 1
				j = pow(2, i)
			if j != x:
				print('-1')
			else:
				count = i // 3
				i = i % 3
				count = count + i // 2
				i = i % 2
				count = count + i
				print(count)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	z = max(a, b)
	y = min(a, b)
	x = z // y
	c = 0
	flag = 0
	if a == b:
		print(0)
	elif z % y != 0:
		print(-1)
	else:
		while x % 2 == 0 or x % 4 == 0 or x % 8 == 0:
			if x % 8 == 0:
				x = x // 8
				c = c + 1
			elif x % 4 == 0:
				x = x // 4
				c = c + 1
			elif x % 2 == 0:
				x = x // 2
				c = c + 1
			if x == 1:
				print(c)
				flag = 1
				break
		if flag == 0:
			print(-1)


test = int(input())

def operacoes(inicial, alvo):
	op = 0
	while True:
		if 8 * inicial == alvo:
			return op + 1
		elif 8 * inicial < alvo:
			inicial *= 8
			op += 1
		else:
			while True:
				if 4 * inicial == alvo:
					return op + 1
				elif 4 * inicial < alvo:
					inicial *= 4
					op += 1
				elif 2 * inicial == alvo:
					return op + 1
				elif 2 * inicial < alvo:
					inicial *= 2
					op += 1
				else:
					return -1
for i in range(test):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	if a > b:
		print(operacoes(b, a))
	if a < b:
		print(operacoes(a, b))


from decimal import Decimal, getcontext
getcontext().prec = 30
t = int(input())
for a in range(t):
	ab = input().split(' ')
	(a, b) = (Decimal(ab[0]), Decimal(ab[1]))
	ma = max(a, b)
	mi = min(a, b)
	c = 0
	while ma > mi:
		ma /= 2
		c += 1
		if ma < mi:
			c = -1
	if c != -1:
		(c3, c2, c1) = (c // 3, c % 3 // 2, c % 3 % 2)
		print(c3 + c2 + c1)
	else:
		print(c)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	x = 0
	ans = 0
	while True:
		if a % 2 ** (x + 1) == 0:
			x += 1
		else:
			break
	y = 0
	while True:
		if b % 2 ** (y + 1) == 0:
			y += 1
		else:
			break
	if a // 2 ** x != b // 2 ** y:
		print(-1)
	else:
		x = abs(x - y)
		if x >= 3:
			ans += x // 3
			x = x % 3
		if x == 2:
			ans += 1
		if x == 1:
			ans += 1
		print(ans)


def fun(k, n):
	if n == 1:
		return k
	elif n % 8 == 0:
		return fun(k + 1, n // 8)
	elif n % 4 == 0:
		return fun(k + 1, n // 4)
	elif n % 2 == 0:
		return fun(k + 1, n // 2)
	else:
		return -1
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	p = max(a, b)
	q = min(a, b)
	if p == q:
		print(0)
	elif p % q == 0:
		print(fun(0, p // q))
	else:
		print(-1)


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	count = 0
	if a > b:
		while a != b:
			if b * 8 <= a:
				b = b * 8
				count += 1
			elif b * 4 <= a:
				b = b * 4
				count += 1
			elif b * 2 <= a:
				b = b * 2
				count += 1
			else:
				count = -1
				break
	elif a < b:
		while a != b:
			if a * 8 <= b:
				a = a * 8
				count += 1
			elif a * 4 <= b:
				a = a * 4
				count += 1
			elif a * 2 <= b:
				a = a * 2
				count += 1
			else:
				count = -1
				break
	print(count)


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	counter = 0
	if n > x:
		while n > x:
			if x * 8 <= n:
				x *= 8
				counter += 1
			elif x * 4 <= n:
				x *= 4
				counter += 1
			else:
				x *= 2
				counter += 1
		if n == x:
			print(counter)
		else:
			print(-1)
	elif n < x:
		while n < x:
			if n * 8 <= x:
				n *= 8
				counter += 1
			elif n * 4 <= x:
				n *= 4
				counter += 1
			else:
				n *= 2
				counter += 1
		if n == x:
			print(counter)
		else:
			print(-1)
	else:
		print(0)


T = int(input())
for _ in range(T):
	(a, b) = map(int, input().split())
	c = a
	d = b
	while c % 2 == 0:
		c = c // 2
	while d % 2 == 0:
		d = d // 2
	if c != d:
		print(-1)
		continue
	mapp = {}
	q = []
	mapp[a] = 1
	q.append([a, 0])
	ans = -1
	while len(q) > 0:
		A = q.pop(0)
		mapp[A[0]] = 1
		if A[0] == b:
			ans = A[1]
			break
		for i in range(2, 9, 2):
			if A[0] * i not in mapp:
				q.append([A[0] * i, A[1] + 1])
				mapp[A[0] * i] = 1
			if A[0] % i == 0 and A[0] // i not in mapp:
				q.append([A[0] // i, A[1] + 1])
				mapp[A[0] // i] = 1
	print(ans)


from math import log, floor

def main():
	T = int(input())
	for _ in range(T):
		(a, b) = map(int, input().split())
		if max(a, b) % min(a, b) != 0:
			print(-1)
		elif a == b:
			print(0)
		else:
			ans = 0
			val = max(b, a) // min(b, a)
			if val & val - 1 == 0:
				log8 = floor(log(val, 8))
				log4 = floor(log(val, 4))
				log2 = floor(log(val, 2))
				if log8 >= 1:
					val = val // pow(8, log8)
					log4 = floor(log(val, 4))
					log2 = floor(log(val, 2))
					ans += log8
					if log4 >= 1:
						val = val // pow(4, log4)
						log2 = floor(log(val, 2))
						ans += log4
						if log2 >= 1:
							val = val // pow(2, log2)
							ans += log2
					elif log2 >= 1:
						val = val // pow(2, log2)
						ans += log2
				elif log4 >= 1:
					val = val // pow(4, log4)
					log2 = floor(log(val, 2))
					ans += log4
					if log2 >= 1:
						val = val // pow(2, log2)
						ans += log2
				elif log2 >= 1:
					val = val // pow(2, log2)
					ans += log2
				print(ans)
			else:
				print(-1)
main()


def solution(a, b):
	if b > a:
		(a, b) = (b, a)
	if a % b != 0:
		return -1
	mul = a // b
	bitpos = 0
	for bitpos in range(80):
		if mul == 1 << bitpos:
			break
	else:
		return -1
	res = 0
	res += bitpos // 3
	bitpos %= 3
	res += bitpos // 2
	bitpos %= 2
	res += bitpos
	return res
n = input()
i = 0
for i in range(int(n)):
	s = input().split(' ')
	a = int(s[0])
	b = int(s[1])
	print(solution(a, b))


t = int(input())
for i in range(t):
	inp = input().split()
	a = int(inp[0])
	b = int(inp[1])
	if b > a:
		tmp = b
		b = a
		a = tmp
	if a % b != 0:
		print(-1)
		continue
	if a == b:
		print(0)
		continue
	c = a // b
	pow2 = 0
	while c != 1:
		c = c // 2
		pow2 = pow2 + 1
	if 2 ** pow2 * b != a:
		print(-1)
		continue
	ops = pow2 // 3
	pow2 = pow2 % 3
	ops = ops + pow2 // 2
	pow2 = pow2 % 2
	ops = ops + pow2
	print(ops)


import sys
from collections import Counter
T = int(input().strip())
for t in range(T):
	(a, b) = list(map(int, input().strip().split()))
	if a > b:
		(b, a) = (a, b)
	if b % a:
		print(-1)
		continue
	r = b // a
	ops = 0
	while r > 1 and r % 2 == 0:
		ops += 1
		r //= 2
	if r == 1:
		print(ops // 3 + (1 if ops % 3 else 0))
	else:
		print(-1)


import sys
import bisect as b
import math
input = sys.stdin.readline
mo = 10 ** 9 + 7

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())

def computeGCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
for i in range(inin()):
	(a, b) = cin()
	if a > b:
		(a, b) = (b, a)
	l = [3, 2, 1]
	po = 0
	x = b // a
	if a == b:
		print(0)
	elif x & x - 1 == 0 and x != 1 and (b % a == 0):
		while x > 1:
			po += 1
			x = x // 2
		ans = po // 3 + po % 3 // 2 + po % 3 % 2
		print(ans)
	else:
		print(-1)


def prog():
	for _ in range(int(input().strip())):
		(a, b) = map(int, input().split())
		if b == a:
			print(0)
		elif b > a:
			worked = False
			for val in range(1, 61):
				a *= 2
				if b == a:
					worked = True
					break
			if not worked:
				print(-1)
			elif val % 3 == 0:
				print(int(val / 3))
			else:
				print(int(val / 3) + 1)
		else:
			worked = False
			for val in range(1, 61):
				b *= 2
				if b == a:
					worked = True
					break
			if not worked:
				print(-1)
			elif val % 3 == 0:
				print(int(val / 3))
			else:
				print(int(val / 3) + 1)
prog()


from math import ceil
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	a_string = bin(a)[2:]
	b_string = bin(b)[2:]
	if a == b:
		print(0)
	elif a > b:
		n = a_string.find(b_string)
		if n != 0 or a_string[len(b_string):].count('1') > 0:
			print(-1)
		else:
			print(ceil((len(a_string) - len(b_string)) / 3))
	elif a_string + '0' * (len(b_string) - len(a_string)) == b_string:
		print(ceil((len(b_string) - len(a_string)) / 3))
	else:
		print(-1)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	m = max(a, b)
	n = min(a, b)
	x = m // n
	if m % n:
		print(-1)
		continue
	s = 0
	for i in [8, 4, 2]:
		while i <= x and x % i == 0:
			x //= i
			s += 1
	if x == 1:
		print(s)
	else:
		print(-1)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	if b % a == 0:
		k = b // a
		count = 0
		while k % 8 == 0:
			count += 1
			k = k // 8
		while k % 4 == 0:
			count += 1
			k = k // 4
		while k % 2 == 0:
			count += 1
			k = k // 2
		if k == 1:
			print(count)
		else:
			print(-1)
	else:
		print(-1)


t = int(input())

def solve(x):
	ans = 0
	ans += x // 3
	x = x % 3
	ans += x // 2
	x = x % 2
	ans += x
	return ans
while t:
	(a, b) = map(int, input().split())
	if a < b:
		(a, b) = (b, a)
	f = bin(a)[2:]
	s = bin(b)[2:]
	if a == b:
		print(0)
		t -= 1
		continue
	sz = len(s)
	if f[:sz] == s:
		f = f[sz:]
		if f.count('1'):
			print(-1)
		else:
			print(solve(f.count('0')))
	else:
		print(-1)
	t -= 1


from sys import *

def log(a, b):
	i = b
	po = 0
	while i <= a:
		i = i << 1
		po += 1
	i = i >> 1
	po -= 1
	return (i, po)

def solve(a, b):
	(ans, po) = log(max(a, b), min(a, b))
	if ans == max(a, b):
		a1 = po // 3
		po = po % 3
		a2 = po // 2
		po = po % 2
		a3 = po
		return int(a1 + a2 + a3)
	return -1
	pass
test = 1
test = int(input())
for t in range(0, test):
	(a, b) = list(map(int, input().split()))
	ans = solve(a, b)
	print(ans)


for _ in range(int(input())):
	(A, B) = list(map(int, input().split()))
	ans = 0
	if A == B:
		print(ans)
	elif A > B:
		if A % B != 0:
			print(-1)
		else:
			t = A // B
			temp = 0
			while t != 1:
				if t % 8 == 0:
					t = t // 8
					ans += 1
				elif t % 4 == 0:
					t = t // 4
					ans += 1
				elif t % 2 == 0:
					t = t // 2
					ans += 1
				else:
					temp = 1
					break
			if temp == 0:
				print(ans)
			else:
				print(-1)
	elif A < B:
		if B % A != 0:
			print(-1)
		else:
			t = B // A
			temp = 0
			while t != 1:
				if t % 8 == 0:
					t = t // 8
					ans += 1
				elif t % 4 == 0:
					t = t // 4
					ans += 1
				elif t % 2 == 0:
					t = t // 2
					ans += 1
				else:
					temp = 1
					break
			if temp == 0:
				print(ans)
			else:
				print(-1)


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
from typing import List
T = int(input())

def solve(a, b):
	if a == b:
		return 0
	if a < b:
		return solve(b, a)
	if a % b != 0:
		return -1
	c = a // b
	d = int(math.log(c, 2))
	if 2 ** d == c:
		return d // 3 if d % 3 == 0 else d // 3 + 1
	return -1
ans = []
for ti in range(T):
	(a, b) = map(int, input().split())
	ans.append(solve(a, b))
print('\n'.join(map(str, ans)))


import math
n = int(input())
while n:
	n -= 1
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	if a == b:
		print(0)
		continue
	if a == 0 or b == 0:
		print(-1)
		continue
	if a > b:
		t = a
		a = b
		b = t
	ans = 0
	if b % a:
		print(-1)
		continue
	else:
		b = b // a
		while b % 8 == 0:
			b = b // 8
			ans += 1
		while b % 4 == 0:
			b = b // 4
			ans += 1
		while b % 2 == 0:
			b = b // 2
			ans += 1
		if b != 1:
			print(-1)
			continue
		else:
			print(ans)


tests = int(input())
for _ in range(tests):
	(n, k) = map(int, input().split())
	(n, k) = (max(n, k), min(n, k))
	p = n // k
	if n % k != 0:
		print(-1)
	else:
		count = 0
		while p % 2 == 0:
			p //= 2
			count += 1
		if p != 1:
			print(-1)
		else:
			print((count + 2) // 3)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	count = 0
	if b < a:
		while b < a:
			if a % 2 != 0:
				break
			a //= 2
			count += 1
	else:
		while b > a:
			a *= 2
			count += 1
	if a == b:
		x = count // 3
		y = count % 3 // 2
		z = count % 3 % 2
		print(x + y + z)
	else:
		print(-1)


from math import ceil, sqrt, log2, floor, pi
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
		continue
	else:
		(b, a) = (max(a, b), min(a, b))
	count = 0
	while b > a:
		if a << 3 <= b:
			a = a << 3
			count += 1
		elif a << 2 <= b:
			a = a << 2
			count += 1
		else:
			a = a << 1
			count += 1
	if a == b:
		print(count)
	else:
		print(-1)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	else:
		(x, y) = (max(a, b), min(a, b))
		if x % y != 0:
			print(-1)
		else:
			n = x // y
			l = [8, 4, 2]
			c = 0
			i = 0
			while n > 1 and i < 3:
				while n >= l[i] and n % l[i] == 0:
					n = n // l[i]
					c += 1
				i += 1
			if c == 0 or n != 1:
				print(-1)
			else:
				print(c)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
		continue
	count = 0
	if a > b:
		k = 0
		while a > b:
			if a % 8 == 0 and a // 8 >= b:
				count += 1
				a = a // 8
			elif a % 4 == 0 and a // 4 >= b:
				count += 1
				a = a // 4
			elif a % 2 == 0:
				a = a // 2
				count += 1
			else:
				k = 1
			if a == b:
				break
			if k == 1:
				break
		if a == b:
			print(count)
		else:
			print(-1)
	else:
		k = 0
		while b > a:
			if a * 8 <= b:
				a = a * 8
				count += 1
			elif a * 4 <= b:
				a = a * 4
				count += 1
			elif a * 2 <= b:
				a = a * 2
				count += 1
			else:
				k = 1
			if k == 1:
				break
		if a == b:
			print(count)
		else:
			print(-1)


import sys
import math
input = sys.stdin.readline

def dec2bin(x):
	ans = []
	while x:
		ans.append(x % 2)
		x //= 2
	return list(reversed(ans))

def operations(x):
	ans = 0
	ans += x // 3
	x %= 3
	if x != 0:
		ans += 1
	return ans
T = int(input())
for t in range(T):
	(a, b) = map(int, input().split(' '))
	a = dec2bin(a)
	b = dec2bin(b)
	can = True
	prefix_len = min(len(a), len(b))
	for i in range(prefix_len):
		if a[i] != b[i]:
			can = False
			break
	if can and sum(a) == sum(b):
		print(operations(len(a) - prefix_len) + operations(len(b) - prefix_len))
		continue
	else:
		print(-1)


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	mi = min(a, b)
	ma = max(a, b)
	cnt = 0
	while mi < ma:
		mi *= 8
		cnt += 1
	if mi == ma:
		print(cnt)
	elif ma == mi // 8 * 4 or ma == mi // 8 * 2 or ma == mi // 8 // 2 or (ma == mi // 8 // 4) or (ma == mi // 8 // 8):
		print(cnt)
	else:
		print(-1)


from sys import stdin, stdout
for testcases in range(int(stdin.readline())):
	(a, b) = map(int, stdin.readline().split())
	if a == b:
		stdout.write('0\n')
	elif max(a, b) % min(a, b) == 0:
		div = max(a, b) // min(a, b)
		total = 0
		while div % 8 == 0:
			total += 1
			div //= 8
		while div % 4 == 0:
			total += 1
			div //= 4
		while div % 2 == 0:
			total += 1
			div //= 2
		if div != 1:
			print(-1)
		else:
			print(total)
	else:
		print(-1)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	flag = 0
	ans = 0
	if b > a:
		(a, b) = (b, a)
	while b != a:
		if a % 8 == 0 and a // 8 >= b:
			a //= 8
			ans += 1
		elif a % 4 == 0 and a // 4 >= b:
			a //= 4
			ans += 1
		elif a % 2 == 0 and a // 2 >= b:
			a //= 2
			ans += 1
		else:
			flag = 1
			break
	if flag == 0:
		print(ans)
	else:
		print(-1)


import math
tc = int(input())
for i in range(tc):
	(a, b) = [int(i) for i in input().split()]
	if a > b:
		(a, b) = (b, a)
	steps = 0
	while a < b:
		a *= 2
		steps += 1
	if a == b:
		print(math.ceil(steps / 3))
	else:
		print(-1)


data = [2]
tmp = 2
while max(data) < 10000000000000000000000:
	tmp *= 2
	data.append(tmp)
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
		continue
	elif a < b:
		tmp = a
		a = b
		b = tmp
	if not data.__contains__(a // b) or a % b != 0:
		print(-1)
	else:
		num = a // b
		num = data.index(num) + 1
		cnt = 0
		cnt += num // 3
		num %= 3
		cnt += num // 2
		num %= 2
		cnt += num
		print(cnt)


t = int(input())

def f(x):
	while x % 2 == 0:
		x = x // 2
	if x != 1:
		return -1
for ab in range(t):
	(a, b) = list(map(int, input().split()))
	if a == b:
		print(0)
		continue
	if a >= b:
		if f(a // b) == -1 or a % b != 0:
			print(-1)
		else:
			count = 0
			l = a // b
			while l >= 8:
				l = l // 8
				count += 1
			while l >= 4:
				l = l // 4
				count += 1
			while l >= 2:
				l = l // 2
				count += 1
			print(count)
	else:
		(a, b) = (b, a)
		if f(a // b) == -1 or a % b != 0:
			print(-1)
		else:
			count = 0
			l = a // b
			while l >= 8:
				l = l // 8
				count += 1
			while l >= 4:
				l = l // 4
				count += 1
			while l >= 2:
				l = l // 2
				count += 1
			print(count)


import sys

def ints():
	return list(map(int, sys.stdin.readline().strip().split()))
tc = int(input())
while tc:
	tc -= 1
	(a1, b1) = map(int, input().split())
	a = max(a1, b1)
	b = min(a1, b1)
	a = str(bin(a))[2:]
	b = str(bin(b))[2:]
	if b == a[:len(b)] and b.count('1') == a.count('1'):
		ans = len(a) - len(b)
		if ans == 0:
			print(0)
		elif ans % 3 == 0:
			print(ans // 3)
		else:
			print(ans // 3 + 1)
	else:
		print(-1)


t = int(input())
while t != 0:
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	elif a > b:
		count = 0
		while b < a:
			b = b * 2
			count += 1
		if b == a:
			p = count // 3
			q = count % 3
			if q == 0:
				print(p)
			elif q == 1:
				print(p + 1)
			else:
				print(p + 1)
		else:
			print(-1)
	else:
		count = 0
		while b > a:
			a = a * 2
			count += 1
		if a == b:
			p = count // 3
			q = count % 3
			if q == 0:
				print(p)
			elif q == 1:
				print(p + 1)
			else:
				print(p + 1)
		else:
			print(-1)
	t -= 1


from math import log
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	k = -1
	if a % b == 0:
		k = a // b
	elif b % a == 0:
		k = b // a
	if k == -1:
		print(-1)
		continue
	y = int(log(k, 2))
	if k != 2 ** y:
		print(-1)
		continue
	ans = 0
	x = int(log(k, 8))
	ans += x
	if x != 0:
		k //= 8 ** x
	if k != 0:
		x = int(log(k, 4))
		ans += x
		if x != 0:
			k //= 4 ** x
		if k != 0:
			x = int(log(k, 2))
			ans += x
	print(ans)


import math
from decimal import *

def equals(x, y):
	return max(x, y) - min(x, y) < 10 ** (-18)
t = int(input())
count = 0
while count < t:
	count += 1
	l = list(map(int, input().split(' ')))
	a = l[0]
	b = l[1]
	d = max(a, b)
	c = min(a, b)
	tcount = 0
	broken = False
	while c < d:
		c *= 2
		tcount += 1
		if c > d:
			broken = True
			break
		elif c == d:
			break
	if broken:
		print(-1)
	else:
		print(math.ceil(tcount / 3))


import sys
input = sys.stdin.buffer.readline
t = int(input())
ans = []
for _ in range(t):
	(a, b) = map(int, input().split())
	if a == b:
		ans.append(0)
	elif a > b:
		r = 1
		while a // r > b:
			r *= 2
		if a == r * b:
			rr = 0
			while 2 ** rr < r:
				rr += 1
			ans.append(rr // 3 + (rr % 3 > 0))
		else:
			ans.append(-1)
	else:
		r = 1
		while a * r < b:
			r *= 2
		if a * r == b:
			rr = 0
			while 2 ** rr < r:
				rr += 1
			ans.append(rr // 3 + (rr % 3 > 0))
		else:
			ans.append(-1)
print('\n'.join(map(str, ans)))


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	p = bin(a)[2:]
	q = bin(b)[2:]
	l = [1, 2, 3]
	if a == b:
		print(0)
		continue
	elif a < b:
		x = len(q) - len(p)
		if p + str('0' * x) == q:
			result = x // 3
			x = x % 3
			result += x // 2
			x = x % 2
			result += x
			print(result)
			continue
		else:
			print(-1)
			continue
	else:
		p1 = q
		q1 = p
		x = len(q1) - len(p1)
		if p1 + str('0' * x) == q1:
			result = x // 3
			x = x % 3
			result += x // 2
			x = x % 2
			result += x
			print(result)
			continue
		else:
			print(-1)
			continue


def sol(n):
	m = 0
	while n % 8 == 0:
		m += 1
		n = n // 8
	while n % 4 == 0:
		m += 1
		n = n // 4
	while n % 2 == 0:
		m += 1
		n = n // 2
	if n == 1:
		return m
	else:
		return -1
t = int(input())
for _ in range(t):
	l = list(map(int, input().split()))
	a = min(l)
	b = max(l)
	if a == b:
		print(0)
	elif b % a != 0:
		print(-1)
	else:
		o = 0
		c = b // a
		m = sol(c)
		print(m)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	count = 0
	if a > b and a % b == 0:
		r = a // b
	elif b >= a and b % a == 0:
		r = b // a
	else:
		r = 0
		print('-1')
	if r != 0:
		while r % 8 == 0:
			r = r // 8
			count += 1
		while r % 4 == 0:
			r = r // 4
			count += 1
		while r % 2 == 0:
			r = r // 2
			count += 1
		if r == 1:
			print(count)
		else:
			print('-1')


T = int(input())

def solve(a, b):
	if a > b:
		handleCase_noDiv(b, a)
	elif a < b:
		handleCase_noDiv(a, b)
	else:
		print(0)

def handleCase(a, b):
	d = b / a
	ret = 0
	for i in [8, 4, 2]:
		if d % i == 0:
			p = getPower(d, i)
			d = d / i ** p
			ret += p
		if d == 1:
			print(int(ret))
			return
	print(-1)

def handleCase_noDiv(a, b):
	counter = 0
	aold = 0
	for i in [8, 4, 2]:
		if a > b:
			a = aold
			counter -= 1
		while a < b:
			aold = a
			a *= i
			counter += 1
			if a == b:
				print(counter)
				return
	print(-1)

def getPower(d, i):
	ret = 0
	while d % i == 0:
		d /= i
		ret += 1
	return ret
while T > 0:
	(a, b) = [int(el) for el in input().split(' ')]
	solve(a, b)
	T -= 1


t = int(input())
while t:
	(a, b) = map(int, input().split())
	(c, an, m) = (0, 0, 0)
	if b % a == 0:
		m = b // a
		while m % 8 == 0:
			m //= 8
			an += 1
		while m % 4 == 0:
			m //= 4
			an += 1
		while m % 2 == 0:
			m //= 2
			an += 1
		if m != 1:
			c = -1
		else:
			c = an
	elif a % b == 0:
		m = a // b
		while m % 8 == 0:
			m //= 8
			an += 1
		while m % 4 == 0:
			m //= 4
			an += 1
		while m % 2 == 0:
			m //= 2
			an += 1
		if m != 1:
			c = -1
		else:
			c = an
	else:
		c = -1
	print(c)
	t -= 1


import math

def get_power_of_two(a):
	i = 0
	r = -1
	p = -1
	while True:
		power = 2 ** i
		if power > a:
			break
		if a % power == 0:
			r = a // power
			p = i
		i += 1
	return (r, p)
T = int(input())
for t in range(T):
	(a, b) = list(map(int, input().split()))
	(r1, p1) = get_power_of_two(a)
	(r2, p2) = get_power_of_two(b)
	if r1 != r2:
		print(-1)
	else:
		res = math.ceil((max(p1, p2) - min(p1, p2) * 1.0) / 3)
		print(res)


for i in range(int(input())):
	(a, b) = list(map(int, input().split()))
	if a > b:
		(a, b) = (b, a)
	que = list()
	que.append(a)
	visited = dict()
	visited[a] = 0
	found = False
	while len(que) > 0:
		curr = que.pop()
		if curr == b:
			print(visited[curr])
			found = True
			break
		t = curr * 2
		v = visited[curr]
		if t not in visited and t <= b:
			visited[t] = v + 1
			que.append(t)
		t = curr * 4
		if t not in visited and t <= b:
			visited[t] = v + 1
			que.append(t)
		t = curr * 8
		if t not in visited and t <= b:
			visited[t] = v + 1
			que.append(t)
	if not found:
		print(-1)


from math import ceil
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	x = a
	y = b
	ax = 0
	by = 0
	while x % 2 == 0 or y % 2 == 0:
		if x % 2 == 0:
			ax += 1
			x //= 2
		if y % 2 == 0:
			by += 1
			y //= 2
	if x != y:
		print('-1')
	else:
		print(ceil(abs(ax - by) / 3))


import math
cases = int(input())
for t in range(cases):
	(a, b) = [int(i) for i in input().split()]
	(a, b) = (min(a, b), max(a, b))
	if b % a == 0:
		if a == b:
			print(0)
		elif b // a % 2 == 1:
			print(-1)
		else:
			k = b // a
			c = 0
			while k:
				if k % 8 == 0:
					c += 1
					k //= 8
				elif k % 4 == 0:
					c += 1
					k //= 4
				elif k % 2 == 0:
					c += 1
					k //= 2
				elif k == 1:
					print(c)
					break
				else:
					print(-1)
					break
	else:
		print(-1)


import math
import sys
t = int(input())

def two_ana(num):
	count = 0
	while num % 2 == 0:
		num = num >> 1
		count += 1
	return (num, count)
for i in range(t):
	inp = input().split(' ')
	(a, b) = (int(inp[0]), int(inp[1]))
	(a_rem, a_pow) = two_ana(a)
	(b_rem, b_pow) = two_ana(b)
	if a_rem != b_rem:
		print(-1)
		continue
	diff = abs(a_pow - b_pow)
	print(int(diff / 3) + int(int(diff % 3) / 2) + int(int(diff % 3) % 2))


t = int(input())
while t > 0:
	t -= 1
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	ans = 0
	while a * 8 <= b:
		a *= 8
		ans += 1
	while a * 4 <= b:
		a *= 4
		ans += 1
	while a * 2 <= b:
		a *= 2
		ans += 1
	if a != b:
		ans = -1
	print(ans)


import sys
input = sys.stdin.readline

def solve():
	(A, B) = map(int, input().split())
	if A == B:
		print(0)
	else:
		if A > B:
			(A, B) = (B, A)
		RESULT = 0
		if B % A != 0:
			print(-1)
		else:
			x = B // A
			t = 0
			for i in range(1, 64):
				if pow(2, i) == x:
					t = i
					break
			if t == 0:
				print(-1)
			else:
				RESULT += t // 3
				t = t % 3
				RESULT += t // 2
				t = t % 2
				RESULT += t
				print(RESULT)
TEST = int(input())
for _ in range(TEST):
	solve()


from sys import stdin, stdout
import math, sys
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import bisect as bi
import heapq

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())
else:

	def I():
		return int(stdin.readline())

	def In():
		return map(int, stdin.readline().split())

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_right(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		(a, b) = In()
		if b > a:
			(a, b) = (b, a)
		if a == b:
			print(0)
			return
		if b == 1:
			if a & 1 == 1:
				print(-1)
			else:
				temp = a // b
				ans = 0
				while temp % 8 == 0:
					ans += 1
					temp = temp // 8
				while temp % 4 == 0:
					ans += 1
					temp = temp // 4
				while temp % 2 == 0:
					ans += 1
					temp = temp // 2
				if temp != 1:
					print(-1)
				else:
					print(ans)
		elif a >= b:
			if a % b == 0:
				temp = a // b
				if temp != 1:
					if temp % 2 != 0:
						print(-1)
						return
				ans = 0
				while temp % 8 == 0:
					ans += 1
					temp = temp // 8
				while temp % 4 == 0:
					ans += 1
					temp = temp // 4
				while temp % 2 == 0:
					ans += 1
					temp = temp // 2
				if temp != 1:
					print(-1)
				else:
					print(ans)
			else:
				print(-1)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(I()):
	main()


def Check(n):
	moves = 0
	while n % 2 == 0:
		n //= 2
		moves += 1
	return (n, moves)

def JohnnyandAncientComputer(a, b):
	total = 0
	if Check(a)[0] != Check(b)[0]:
		return -1
	distancia = abs(Check(a)[1] - Check(b)[1])
	while distancia - 3 >= 0:
		distancia -= 3
		total += 1
	while distancia - 2 >= 0:
		distancia -= 2
		total += 1
	while distancia - 1 >= 0:
		distancia -= 1
		total += 1
	return total
Lista = []
total = int(input())
for i in range(total):
	All = [int(i) for i in input().split()]
	Lista.append(All)
for j in Lista:
	print(JohnnyandAncientComputer(j[0], j[1]))


def divisible_2(num):
	temp = 1
	while temp < num:
		temp *= 2
	if temp == num:
		return True
	else:
		return False
import math
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
		continue
	if max(a, b) % min(a, b) != 0:
		print(-1)
		continue
	temp = max(a, b) // min(a, b)
	answer = divisible_2(temp)
	if not answer:
		print(-1)
		continue
	value = 0
	while temp > 1:
		temp = temp // 2
		value += 1
	pos = math.ceil(value / 3)
	print(pos)


from sys import stdin, gettrace
if gettrace():
	inputi = input
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()

def main():

	def solve():
		(a, b) = map(int, inputi().split())
		if b >= a:
			count = 0
			while b >= a * 8:
				a = a * 8
				count += 1
			if b >= a * 4:
				a = a * 4
				count += 1
			if b >= a * 2:
				a = a * 2
				count += 1
			if b == a:
				print(count)
			else:
				print(-1)
		else:
			count = 0
			while b <= a // 8 and a % 8 == 0:
				a = a // 8
				count += 1
			if b <= a // 4 and a % 4 == 0:
				a = a // 4
				count += 1
			if b <= a // 2 and a % 2 == 0:
				a = a // 2
				count += 1
			if b == a:
				print(count)
			else:
				print(-1)
	q = int(inputi())
	for _ in range(q):
		solve()
main()


for iota in range(int(input())):
	(a, b) = tuple(map(int, input().split()))
	if a == b:
		print(0)
		continue
	if a > b and a % 2 == 1:
		print(-1)
		continue
	if a < b and b % 2 == 1:
		print(-1)
		continue
	count = 0
	sett = True
	if a < b:
		while True:
			b //= 2
			if a == b:
				count += 1
				break
			if b % 2 == 1:
				sett = False
				break
			if a < b:
				count += 1
				continue
			if a > b:
				sett = False
				break
	if a > b:
		while True:
			b *= 2
			if a == b:
				count += 1
				break
			if a > b:
				count += 1
				continue
			if a < b:
				sett = False
				break
	if sett:
		print(count // 3 + count % 3 // 2 + count % 3 % 2)
	else:
		print(-1)


def solve(a, b):
	count = 0
	while a % 8 == 0 and a // 8 >= b:
		count += 1
		a = a // 8
		if a < b:
			break
	while a % 4 == 0 and a // 4 >= b:
		count += 1
		a = a // 4
		if a < b:
			break
	while a % 2 == 0 and a // 2 >= b:
		count += 1
		a = a // 2
		if a < b:
			break
	if a != b:
		return -1
	return count

def solution():
	i = input()
	a = int(i.split(' ')[0])
	b = int(i.split(' ')[1])
	if a > b:
		print(solve(a, b))
	elif a < b:
		print(solve(b, a))
	elif a == b:
		print(0)
t = int(input())
for i in range(t):
	solution()


for i in range(int(input())):
	(a, b) = map(int, input().split())
	cnt = 0
	t1 = 0
	if a > b:
		while a > b:
			if a % 2 == 0:
				tmp1 = a // 2
				if a % 4 == 0:
					tmp2 = a // 4
				else:
					tmp2 = 0
				if a % 8 == 0:
					tmp3 = a // 8
				else:
					tmp3 = 0
				if tmp1 >= b:
					a = tmp1
				if tmp2 >= b:
					a = tmp2
				if tmp3 >= b:
					a = tmp3
				cnt += 1
			else:
				break
			if a != tmp1 and a != tmp2 and (a != tmp3):
				break
	else:
		while a < b:
			tmp1 = a * 2
			tmp2 = a * 4
			tmp3 = a * 8
			if tmp1 <= b:
				a = tmp1
			if tmp2 <= b:
				a = tmp2
			if tmp3 <= b:
				a = tmp3
			if a != tmp1 and a != tmp2 and (a != tmp3):
				break
			cnt += 1
	if a == b:
		print(cnt)
	else:
		print(-1)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log, pi, sin
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
dp = dd(int)
dp[0] = 1
for i in range(1, 65):
	dp[i] = 2 * dp[i - 1]
for _ in range(int(data())):
	(a, b) = sp()
	if a % b != 0 and b % a != 0:
		out(-1)
		continue
	if a % b == 0:
		temp = a // b
	else:
		temp = b // a
	if temp in dp.values():
		for i in dp.keys():
			if dp[i] == temp:
				out(ceil(i / 3))
				break
	else:
		out(-1)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	(a, b, k) = (max(a, b), min(a, b), 0)
	while a > b and a % 2 == 0:
		(a, k) = (a // 2, k + 1)
	if a == b:
		if k % 3 == 0:
			print(k // 3)
		else:
			print(k // 3 + 1)
	else:
		print(-1)


def isPowerOfTwo(n):
	if n == 0:
		return False
	while n != 1:
		if n % 2 != 0:
			return False
		n = n // 2
	return True
for i in range(0, int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	elif max(a, b) % min(a, b) != 0:
		print(-1)
	else:
		c = max(a, b) // min(a, b)
		if isPowerOfTwo(c):
			n = 0
			while c % 8 == 0:
				n += 1
				c = c // 8
			while c % 4 == 0:
				n += 1
				c = c // 4
			n += c // 2
			print(n)
		else:
			print(-1)


import math
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	ops = 0
	while a < b:
		a <<= 1
		ops += 1
	if a == b:
		print((ops + 2) // 3)
	else:
		print(-1)


num = int(input(''))
for i in range(num):
	(b, a) = sorted(list(map(int, input('').split(' '))))
	countlist = []
	while a > b:
		b *= 8
		countlist.append(1)
	if a == b:
		print(len(countlist))
	elif a * 4 == b or a * 2 == b:
		print(len(countlist))
	else:
		print('-1')


def main():
	(n, k) = [int(x) for x in input().split()]
	max_ = max(n, k)
	min_ = min(n, k)
	if max_ % min_ != 0:
		return -1
	x = max_ // min_
	q = 0
	while x % 2 == 0:
		q += 1
		x //= 2
	if x == 1:
		if q % 3 == 0:
			return q // 3
		return q // 3 + 1
	return -1
t = int(input())
for fd in range(t):
	print(main())


import math
from random import randint

def get_odd(n):
	while n % 2 == 0:
		n = n >> 1
	return n

def my_soln(a, b):
	if a == b:
		return 0
	if a < b:
		(a, b) = (b, a)
	if get_odd(a) != get_odd(b):
		return -1
	else:
		t = math.log2(a / b)
		if t != int(t):
			return -1
		else:
			twos = t
			ans = 0
			(quo, r) = divmod(twos, 3)
			ans += quo
			twos = r
			(quo, r) = divmod(twos, 2)
			ans += quo
			twos = r
			(quo, r) = divmod(twos, 1)
			ans += quo
			return int(ans)
from sys import stdin, stdout
q = int(input())
for _ in range(q):
	(a, b) = map(int, input().split())
	print(my_soln(a, b))


def get_steps(num):
	step = 0
	while True:
		if num == 1:
			return step
			break
		if num % 8 == 0:
			num = num // 8
		elif num % 4 == 0:
			num = num // 4
		elif num % 2 == 0:
			num = num // 2
		else:
			break
		step += 1
	return -1
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a < b:
		if b % a != 0:
			print(-1)
		else:
			num = b // a
			print(get_steps(num))
	elif a % b != 0:
		print(-1)
	else:
		num = a // b
		print(get_steps(num))


def solution(a, b):
	(a, b) = (min(a, b), max(a, b))
	cnt = 0
	while a < b:
		a *= 2
		cnt += 1
	return (cnt + 2) // 3 if a == b else -1
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split(' '))
	print(solution(a, b))


import math
for i in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
		continue
	(b, a) = (max(a, b), min(a, b))
	ans = 0
	while a < b:
		if a * 8 <= b:
			a *= 8
			ans += 1
			continue
		if a * 4 <= b:
			a *= 4
			ans += 1
			continue
		if a * 2 <= b:
			ans += 1
			a *= 2
			continue
		break
	if a != b:
		print(-1)
	else:
		print(ans)


t = int(input())
while t:
	t = t - 1
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
		continue
	if a > b:
		x = a / b
		if x == a // b:
			cnt = 1
			c = 2
			while c < x:
				cnt += 1
				c *= 2
			if c == x:
				out = cnt // 3
				cnt %= 3
				out += cnt // 2
				cnt %= 2
				out += cnt
				print(out)
			else:
				print(-1)
		else:
			print(-1)
	else:
		x = b / a
		if x == b // a:
			cnt = 1
			c = 2
			while c < x:
				cnt += 1
				c *= 2
			if c == x:
				out = cnt // 3
				cnt %= 3
				out += cnt // 2
				cnt %= 2
				out += cnt
				print(out)
			else:
				print(-1)
		else:
			print(-1)


def f(n, m):
	a = max(n, m)
	b = min(n, m)
	steps = 0
	while a >= b:
		reduce = False
		for x in [8, 4, 2]:
			if a // x >= b and (not reduce) and (a % x == 0):
				a //= x
				reduce = True
				steps += 1
		if a == b:
			print(steps)
			return
		if not reduce:
			print('-1')
			return
t = int(input())
for _ in range(t):
	(a, b) = input().split(' ')
	(a, b) = (int(a), int(b))
	f(a, b)


for i in range(int(input())):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	n = 0
	end = False
	while not end:
		if a == b:
			print(n)
			end = True
		elif a < b:
			n += 1
			a *= 2
			if a == b:
				print(n)
				end = True
			elif a > b:
				print(-1)
				end = True
			elif a < b:
				a *= 2
				if a == b:
					print(n)
					end = True
				elif a > b:
					print(-1)
					end = True
				elif a < b:
					a *= 2
					if a == b:
						print(n)
						end = True
					elif a > b:
						print(-1)
						end = True
		elif a > b:
			n += 1
			if a % 2 == 0:
				a = a >> 1
				if a == b:
					print(n)
					end = True
				elif a < b:
					print(-1)
					end = True
				elif a > b:
					if a % 2 == 0:
						a = a >> 1
						if a == b:
							print(n)
							end = True
						elif a < b:
							print(-1)
							end = True
						elif a > b:
							if a % 2 == 0:
								a = a >> 1
								if a == b:
									print(n)
									end = True
								elif a < b:
									print(-1)
									end = True
							else:
								print(-1)
								end = True
					else:
						print(-1)
						end = True
			else:
				print(-1)
				end = True


from math import *
from io import BytesIO, IOBase
import sys
import os
inf = float('inf')

def Iint():
	return int(input())

def Ilist():
	return list(map(int, input().split()))

def Imap():
	return map(int, input().split())

def Plist(li, s=' '):
	print(s.join(map(str, li)))

def main():
	pow2 = dict()
	for i in range(61):
		pow2[1 << i] = i
	t = Iint()
	for _ in range(t):
		(a, b) = Imap()
		if a == b:
			print(0)
		elif a < b:
			if b % a == 0 and b // a in pow2:
				x = pow2[b // a]
				if x % 3 == 0:
					x = x // 3
				else:
					x = ceil(x / 3)
				print(x)
			else:
				print(-1)
		elif a > b:
			if a % b == 0 and a // b in pow2:
				x = pow2[a // b]
				if x % 3 == 0:
					x = x // 3
				else:
					x = ceil(x / 3)
				print(x)
			else:
				print(-1)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
main()


a = int(input())
for i in range(a):
	(b, c) = map(int, input().split())
	d = max(b, c)
	e = min(b, c)
	ct = 0
	if b == c:
		print(0)
	elif d // e % 2 != 0 or d % e != 0:
		print(-1)
	else:
		while e < d:
			if d // e % 8 == 0 and d % e == 0:
				d = d // 8
				ct += 1
			elif d // e % 4 == 0 and d % e == 0:
				d = d // 4
				ct += 1
			elif d // e % 2 == 0 and d % e == 0:
				d = d // 2
				ct += 1
			else:
				break
		if e == d:
			print(ct)
		else:
			print(-1)


def nop2(a):
	p = 0
	while a % 2 == 0:
		a //= 2
		p += 1
	return [a, p]
for xyz in range(0, int(input())):
	(a, b) = map(int, input().split())
	la = nop2(a)
	lb = nop2(b)
	a = 0
	if la[0] == lb[0]:
		d = abs(la[1] - lb[1])
		a += d // 3
		d %= 3
		a += d // 2
		d %= 2
		a += d
		d %= 1
		print(a)
	else:
		print(-1)


from sys import stdin, stdout

def solve(a, b):
	if a == 1 and b % 2 and (b != 1):
		return -1
	if a == b:
		return 0
	if b % a != 0:
		return -1
	count = 0
	while a << 3 <= b:
		a <<= 3
		count += 1
	if a == b:
		return count
	while a << 2 <= b:
		a <<= 2
		count += 1
	if a == b:
		return count
	while a << 1 <= b:
		a <<= 1
		count += 1
	if a == b:
		return count
	if a < b:
		return -1
	while a % 8 == 0:
		a >>= 3
		count += 1
	if a == b:
		return count
	while a % 4 == 0:
		a >>= 2
		count += 1
	if a == b:
		return count
	while a % 2 == 0:
		a >>= 1
		count += 1
	if a > b:
		return -1
	return count
t = int(stdin.readline())
for _ in range(t):
	(a, b) = map(int, stdin.readline().split())
	if a > b:
		(a, b) = (b, a)
	stdout.write(f'{solve(a, b)}\n')


from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math

def get_int():
	return int(stdin.readline().strip())

def get_tuple():
	return map(int, stdin.readline().split())

def get_list():
	return list(map(int, stdin.readline().split()))

def sub(st):
	r = 0
	for (i, val) in enumerate(st):
		if val == '1':
			r = i
	return r

def solve():
	(a, b) = get_tuple()
	st1 = bin(a)[2:]
	st2 = bin(b)[2:]
	r1 = sub(st1)
	r2 = sub(st2)
	if st1[:r1 + 1] == st2[:r2 + 1]:
		ans = abs(len(st1) - r1 - (len(st2) - r2))
		count = ans // 3
		ans = ans % 3
		count += ans // 2
		ans = ans % 2
		count += ans
		print(count)
	else:
		print(-1)

def main():
	solve()
TestCases = True
if TestCases:
	for i in range(get_int()):
		main()
else:
	main()


def check(n):
	count = 0
	if n == 0:
		return False
	while n != 1:
		if n % 2 != 0:
			return (1, False)
		n = n // 2
		count += 1
	return (count, True)

def answer(a, b):
	if a == b:
		return 0
	if a > b:
		if a % b != 0:
			return -1
		else:
			x = a // b
			(y, flag) = check(x)
			if flag:
				p = y // 3
				f = y % 3
				q = f // 2
				if f % 2 == 0:
					return p + q
				else:
					return p + q + 1
			else:
				return -1
	if a < b:
		if b % a != 0:
			return -1
		else:
			x = b // a
			(y, flag) = check(x)
			if flag:
				p = y // 3
				f = y % 3
				q = f // 2
				if f % 2 == 0:
					return p + q
				else:
					return p + q + 1
			else:
				return -1
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	print(int(answer(a, b)))


import math

def solve(m, n):
	if m < n:
		return solve(n, m)
	if m % n != 0:
		return -1
	elif m == n:
		return 0
	elif m // n and (not m // n & m // n - 1):
		s = math.log2(m // n)
		ans = 0
		ans += s // 3
		s = s - 3 * (s // 3)
		if s > 0:
			ans += 1
		return int(ans)
	else:
		return -1
for _ in range(int(input())):
	(m, n) = map(int, input().split())
	print(solve(m, n))


import sys
buff_readline = sys.stdin.readline
readline = sys.stdin.readline
INF = 2 ** 62 - 1

def read_int():
	return int(buff_readline())

def read_int_n():
	return list(map(int, buff_readline().split()))

def read_float():
	return float(buff_readline())

def read_float_n():
	return list(map(float, buff_readline().split()))

def read_str():
	return readline().strip()

def read_str_n():
	return readline().strip().split()

def error_print(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time

	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		error_print(e - s, 'sec')
		return ret
	return wrap

def slv(A, B):
	a = A
	b = B
	while a != 0 and a & 1 == 0:
		a >>= 1
	while b != 0 and b & 1 == 0:
		b >>= 1
	if a != b:
		return -1
	a = A
	b = B
	if a > b:
		(a, b) = (b, a)
	for i in range(1000):
		if a << i == b:
			break
	return -(-i // 3)

def main():
	T = read_int()
	for _ in range(T):
		(A, B) = read_int_n()
		print(slv(A, B))
main()


t = int(input())
while t > 0:
	(x, y) = input().split()
	(x, y) = (int(x), int(y))
	z = max(x, y) // min(x, y)
	if x == y:
		print(0)
	elif x % 2 != 0 and y % 2 != 0:
		print(-1)
	elif max(x, y) % min(x, y) != 0:
		print(-1)
	elif z == 2 or z == 4 or z == 8:
		print(1)
	else:
		a = 0
		while z % 2 == 0:
			z = z // 2
			a += 1
		if a == 0 or 2 ** a != max(x, y) // min(x, y):
			print(-1)
		else:
			print(a // 3 + (a - a // 3 * 3) // 2 + (a - (a - a // 3 * 3) // 2 * 2) - a // 3 * 3)
	t -= 1


t = int(input())

def to(val):
	string = ''
	while val > 0:
		string = str(val % 2) + string
		val = val // 2
	return string

def count(string):
	cnt = 0
	for i in string:
		if i == '1':
			cnt += 1
	return cnt
while t:
	t -= 1
	(a, b) = input().split()
	a = to(int(a))
	b = to(int(b))
	pos = 0
	if len(a) < len(b):
		pos = b.find(a)
	else:
		pos = a.find(b)
	if pos != -1 and count(a) == count(b):
		val = max(len(a), len(b)) - min(len(a), len(b))
		ans = 0
		if val:
			ans = 0
		if val <= 3 and (not val == 0):
			ans = 1
		if val > 3:
			ans += val // 3
			val -= val // 3 * 3
			if val > 0:
				ans += 1
		print(ans)
	else:
		print(-1)


import math
t = int(input())
for whataboutcoffie in range(t):
	(n, m) = list(map(int, input().split()))
	deff = 0
	res = 0
	k = 0
	if n > m:
		if n % m == 0:
			k = n // m
			deff = 1
	elif m % n == 0:
		k = m // n
		deff = 2
	if deff == 0 or (k % 2 == 1 and k != 1):
		print(-1)
	else:
		while k >= 8 and k % 8 == 0:
			res += 1
			k = k // 8
		while k >= 4 and k % 4 == 0:
			res += 1
			k = k // 4
		while k >= 2 and k % 2 == 0:
			res += 1
			k = k // 2
		if k != 1:
			print(-1)
		else:
			print(res)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import math
testcases = int(input())
for j in range(testcases):
	(a, b) = map(int, input().split())
	outy = 0
	power = 0
	if a > b:
		(a, b) = (b, a)
	while a < b:
		a *= 2
		power += 1
	if a == b:
		print(math.ceil(power / 3))
	else:
		print(-1)


n = int(input())
for i in range(n):
	(x, z) = input().split(' ')
	x = bin(int(x))[2:]
	z = bin(int(z))[2:]
	if x > z:
		(x, z) = (z, x)
	if x == z[:len(x)]:
		if set(z[len(x):]) == {'0'}:
			size = len(z) - len(x)
			rez = size // 3
			size = size % 3
			rez += size // 2
			size = size % 2
			rez += size
			print(rez)
		elif not set(z[len(x):]):
			print(0)
		else:
			print(-1)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	(a, b) = list(map(int, input().split(' ')))
	if a == b:
		print(0)
		continue
	(a, b) = (b, a) if b > a else (a, b)
	if a % b == 0:
		quotient = a // b
		if quotient & quotient - 1 == 0:
			ans = 1
			while quotient > 8:
				ans += 1
				quotient = quotient >> 3
			print(ans)
		else:
			print(-1)
	else:
		print(-1)


def count(a, b):
	x = [2, 4, 8]
	(c, i) = (0, 2)
	if a > b:
		(a, b) = (b, a)
	elif a == b:
		return 0
	if b % a != 0:
		return -1
	else:
		while a < b and i >= 0:
			if a * x[i] <= b:
				a = a * x[i]
				c += 1
			else:
				i -= 1
		if a == b:
			return c
		else:
			return -1
for i in range(int(input())):
	(a, b) = map(int, input().split())
	print(count(a, b))


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	else:
		ct = 0
		ok = True
		if a > b:
			while a != b:
				if a % 2 != 0:
					ok = False
					break
				a >>= 1
				ct += 1
				if a < b:
					ok = False
					break
		else:
			while a != b:
				a <<= 1
				ct += 1
				if a > b:
					ok = False
					break
		if ok:
			ans = ct // 3
			if ct % 3:
				ans += 1
			print(ans)
		else:
			print(-1)


def main():
	t = int(input())
	for i in range(t):
		(a, b) = map(int, input().split())
		if a == b:
			print(0)
			continue
		if a > b:
			(b, a) = (a, b)
		if b % a != 0:
			print(-1)
			continue
		c = b // a
		count = 0
		while c % 2 == 0:
			c //= 2
			count += 1
		if c != 1:
			print(-1)
			continue
		dp = [1000000000 for i in range(count + 1)]
		dp[0] = 0
		for j in range(1, count + 1):
			for u in [1, 2, 3]:
				if j - u >= 0:
					dp[j] = min(dp[j], dp[j - u] + 1)
		print(dp[count])
main()


import math
t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	if n == x:
		print('0')
	elif max(n, x) % min(n, x) != 0:
		print('-1')
	else:
		ans = 0
		count = 0
		ma = max(n, x)
		mi = min(n, x)
		ans = ma // mi
		temp = ans
		flag = 0
		while temp > 1:
			if temp % 2 != 0:
				flag = 1
				break
			temp = temp // 2
		if flag == 1:
			print('-1')
		else:
			while ans % 8 == 0:
				count += 1
				ans = ans // 8
			while ans % 4 == 0:
				count += 1
				ans = ans // 4
			while ans % 2 == 0:
				count += 1
				ans = ans // 2
			print(count)


t = int(input())
while t > 0:
	(a, b) = map(int, input().split())
	(a, b) = (max(a, b), min(a, b))
	if a % b != 0:
		print('-1')
	else:
		c = 0
		while a > b:
			b *= 2
			c += 1
		if a != b:
			print('-1')
		else:
			print(c // 3 + c % 3 // 2 + c % 3 % 2)
	t -= 1


import math
from decimal import *
getcontext().prec = 30
t = int(input())
while t:
	t -= 1
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	if b % a:
		print(-1)
		continue
	mul = b // a
	if mul & mul - 1 == 0:
		print(math.ceil(math.log(mul, 2) / 3))
	else:
		print(-1)


from sys import stdin

def inp():
	return stdin.readline().strip()
t = int(inp())
for _ in range(t):
	(a, b) = [int(x) for x in inp().split()]
	c2 = 0
	c4 = 0
	c8 = 0
	if a == b:
		print(0)
		continue
	if a > b:
		while True:
			if a == b:
				print(c2 + c4 + c8)
				break
			if a % 2 != 0 and b == 1:
				print(-1)
				break
			elif a % b != 0:
				print(-1)
				break
			elif a < b:
				print(-1)
				break
			else:
				a //= 2
				c2 += 1
				if c2 == 2:
					c2 = 0
					c4 += 1
				if c4 == 1 and c2 == 1:
					c4 = 0
					c2 = 0
					c8 += 1
	else:
		while True:
			if a == b:
				print(c2 + c4 + c8)
				break
			elif a > b:
				print(-1)
				break
			else:
				a *= 2
				c2 += 1
				if c2 == 2:
					c2 = 0
					c4 += 1
				if c4 == 1 and c2 == 1:
					c4 = 0
					c2 = 0
					c8 += 1


from sys import stdin

def func(a, b):
	for (i, j) in ((a, b), (b, a)):
		if i == j:
			return 0
		if i > j:
			(d, m) = divmod(i, j)
			if m:
				break
			ret = 0
			for k in (8, 4, 2):
				while 1:
					if not d % k:
						d //= k
						ret += 1
						if d == 1:
							return ret
					else:
						break
	return -1

def main():
	input = lambda : stdin.readline()[:-1]
	T = int(input())
	for _ in [0] * T:
		(A, B) = map(int, input().split())
		print(func(A, B))
main()


for i in range(int(input())):
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	(d, d1, rem, rem1) = (0, 0, 0, 0)
	while 1:
		if b % 2 == 0:
			b //= 2
			d += 1
		else:
			rem = b
			break
	while 1:
		if a % 2 == 0:
			a //= 2
			d1 += 1
		else:
			rem1 = a
			break
	if rem != rem1:
		print('-1')
	else:
		ans = 0
		t = d - d1
		e = t // 3
		f = (t - e * 3) // 2
		tw = t - e * 3 - f * 2
		print(f + e + tw)


import math
t = int(input())
for _ in range(t):
	(a, b) = [int(x) for x in input().split()]
	if b % a == 0 and b // a & b // a - 1 == 0:
		print(math.ceil(int(math.log2(b // a)) / 3))
	elif a % b == 0 and a // b & a // b - 1 == 0:
		print(math.ceil(int(math.log2(a // b)) / 3))
	else:
		print(-1)


T = 1
T = int(input())
for ti in range(1, T + 1):
	(a, b) = input().split()
	(a, b) = tuple(map(int, (a, b)))
	(a, b) = (max([a, b]), min([a, b]))
	factor = a // b
	reminder = a % b
	if reminder == 0:
		log2 = 0
		allgood = True
		while factor > 1:
			if factor % 2:
				allgood = False
				break
			log2 += 1
			factor = factor // 2
		if allgood:
			log8 = log2 // 3 + (1 if log2 % 3 else 0)
			print(log8)
		else:
			print(-1)
	else:
		print(-1)


from sys import stdin, stdout
from math import *
from heapq import *
from collections import *

def main():
	ntest = int(stdin.readline())
	for testc in range(ntest):
		(a, b) = [int(c) for c in stdin.readline().split()]
		res = 0
		x = a
		y = b
		while x % 2 == 0:
			x = x // 2
		while y % 2 == 0:
			y = y // 2
		if x != y:
			stdout.write('-1\n')
			continue
		res = 0
		if a < b:
			stop = False
			while a < b and stop == False:
				stop = True
				for i in [8, 4, 2]:
					if a * i <= b:
						a = a * i
						stop = False
						res += 1
						break
		elif a > b:
			stop = False
			while a > b and stop == False:
				stop = True
				for i in [8, 4, 2]:
					if a // i >= b and a % i == 0:
						a = a // i
						stop = False
						res += 1
						break
		if a == b:
			stdout.write('%d\n' % res)
		else:
			stdout.write('-1\n')
	return 0
main()


from sys import stdin, stdout
read = stdin.readline

def puts(x, end='\n'):
	stdout.write(x + end)

def read_int():
	return int(read())

def list_in():
	return [i for i in read().split()]

def int_list_in():
	return [int(i) for i in read().split()]

def solve():
	(a, b) = int_list_in()
	bina = bin(a)[2:]
	binb = bin(b)[2:]
	if bina.rstrip('0') == binb.rstrip('0'):
		bits = abs(len(bina) - len(binb))
	else:
		puts('-1')
		return
	final = bits // 3
	bits = bits % 3
	final += bits // 2
	bits = bits % 2
	final += bits
	print(final)
for i in range(read_int()):
	solve()


def fun(a):
	while a % 2 == 0:
		a //= 2
	return a
t = int(input())
while t:
	t -= 1
	(a, b) = [int(x) for x in input().split()]
	z = fun(a)
	if z != fun(b):
		print(-1)
		continue
	if a == b:
		print(0)
		continue
	if a > b:
		(a, b) = (b, a)
	x = b // a
	c = 0
	while x > 1:
		if x % 8 == 0:
			x = x // 8
			c += 1
		elif x % 4 == 0:
			x = x // 4
			c += 1
		elif x % 2 == 0:
			x = x // 2
			c += 1
	print(c)


from math import log, ceil
from sys import stdin, stdout
int_in = lambda : int(stdin.readline())
arr_in = lambda : [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for y in range(rows)]
str_in = lambda : stdin.readline().strip()
out = lambda o: stdout.write('{}\n'.format(o))
arr_out = lambda o: out(' '.join(map(str, o)))
bool_out = lambda o: out('YES' if o else 'NO')
tests = lambda : range(1, int_in() + 1)
case_out = lambda i, o: out('Case #{}: {}'.format(i, o))

def solve(a, b):
	if a == b:
		return 0
	elif b > a:
		if b % a != 0:
			return -1
		need = b // a
		if bin(need).count('1') > 1:
			return -1
		total = log(need, 2)
		return ceil(total / 3)
	else:
		if a % b != 0:
			return -1
		need = a // b
		if bin(need).count('1') > 1:
			return -1
		total = log(need, 2)
		return ceil(total / 3)
for i in tests():
	(a, b) = arr_in()
	out(solve(a, b))


t = int(input())
for i in range(t):
	(x, y) = map(int, input().split())
	cnt = 0
	if x > y:
		m = x
		x = y
		y = m
	flag = True
	while y > x and flag:
		x *= 8
		cnt += 1
	if x == y:
		flag = False
	else:
		cnt -= 1
		x //= 8
	while flag and y > x:
		x *= 4
		cnt += 1
	if x == y:
		flag = False
	else:
		cnt -= 1
		x //= 4
	while flag and y > x:
		x *= 2
		cnt += 1
	if x == y:
		flag = False
	else:
		cnt -= 1
		x //= 8
	if x == y:
		print(cnt)
	else:
		print('-1')


def answer(a, b):
	sm = min(a, b)
	gr = max(a, b)
	steps = 0
	while sm < gr:
		sm = sm << 1
		steps += 1
	if sm > gr:
		return -1
	ans = steps // 3 + min(steps % 3, 1)
	return ans

def main():
	t = int(input())
	a = [0] * t
	b = [0] * t
	for j in range(t):
		(a[j], b[j]) = [int(i) for i in input().split()]
	for j in range(t):
		print(answer(a[j], b[j]))
main()


import math
t = int(input())
for _ in range(t):
	(a, b) = list(map(int, input().rstrip().split()))
	if a == b:
		print(0)
		continue
	if a > b:
		(a, b) = (b, a)
	if b % a != 0:
		print(-1)
		continue
	else:
		q = b // a
		bin_q = bin(q)[2:]
		x = list(bin_q)
		if x.count('1') != 1:
			print(-1)
		else:
			num = int(math.log(q, 2))
			if num % 3 == 0:
				print(int(num // 3))
			else:
				print(int(num // 3) + 1)


from collections import defaultdict as dfd
import math
import sys
import heapq

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def main():
	for _ in range(int(input())):
		(a, b) = MI()
		val = 0
		if b > a:
			while a < b:
				a *= 2
				val += 1
			if a != b:
				print(-1)
			else:
				temp = 0
				temp += val // 3
				temp += val % 3 // 2
				temp += val % 3 % 2 // 1
				print(temp)
		elif a == b:
			print(0)
		else:
			while b < a:
				b *= 2
				val += 1
			if a != b:
				print(-1)
			else:
				temp = 0
				temp += val // 3
				temp += val % 3 // 2
				temp += val % 3 % 2 // 1
				print(temp)
main()


from math import ceil
t = int(input())
for tc in range(t):
	(a, b) = [int(x) for x in input().split()]
	ma = max(a, b)
	mi = min(a, b)
	c = 0
	while mi < ma:
		mi *= 2
		c += 1
	if mi != ma:
		print(-1)
	else:
		print(ceil(c / 3))


from math import log2
T = int(input())
while T:
	(a, b) = map(int, input().split())
	x = max(a, b)
	y = min(a, b)
	if x % y != 0:
		print(-1)
	else:
		z = x // y
		d = int(log2(z))
		if 2 ** d != z:
			print(-1)
		else:
			q1 = d // 3
			d = d - q1 * 3
			q2 = d // 2
			d = d - q2 * 2
			q3 = d
			print(q1 + q2 + q3)
	T = T - 1


import math
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
		continue
	if b > a:
		if b % a == 0:
			k = b // a
			l = 0
			while k % 2 == 0:
				k = k // 2
				l += 1
			if k != 1:
				print(-1)
				continue
			r = l
			c = 0
			c += r // 3
			r = r % 3
			c += r // 2
			r = r % 2
			c += r // 1
		else:
			print(-1)
			continue
	else:
		temp = a
		a = b
		b = temp
		if b % a == 0:
			k = b // a
			l = 0
			while k % 2 == 0:
				k = k // 2
				l += 1
			if k != 1:
				print(-1)
				continue
			r = l
			c = 0
			c += r // 3
			r = r % 3
			c += r // 2
			r = r % 2
			c += r // 1
		else:
			print(-1)
			continue
	print(c)


def getSeed(num):
	while num % 2 == 0:
		num //= 2
	return num

def solve():
	(a, b) = map(int, input().split())
	if getSeed(a) != getSeed(b):
		print(-1)
	else:
		if a > b:
			(a, b) = (b, a)
		gap = b // a
		cnt = 0
		while gap >= 8:
			cnt += 1
			gap //= 8
		if gap > 1:
			cnt += 1
		print(cnt)
for _ in range(int(input())):
	solve()


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	(c, v) = (0, 1)
	if b < a:
		v = 8
		while v != 1:
			if a // v < b or a % v != 0:
				v //= 2
			else:
				c += 1
				a //= v
	else:
		v = 8
		while v != 1:
			if a * v > b:
				v //= 2
			else:
				a *= v
				c += 1
	if b == a:
		print(c)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	(n, tar) = map(int, input().split())
	if n == tar:
		print('0')
	elif n < tar:
		count = 0
		while n < tar:
			n = n << 1
			count += 1
		if n != tar:
			print('-1')
			continue
		if count % 3 == 0:
			print(count // 3)
			continue
		else:
			print(count // 3 + 1)
			continue
	else:
		count = 0
		while n > tar:
			if n % 2 != 0:
				break
			n = n >> 1
			count += 1
		if n != tar:
			print('-1')
			continue
		if count % 3 == 0:
			print(count // 3)
			continue
		else:
			print(count // 3 + 1)
			continue


from math import log2

def main():
	for _ in range(int(input())):
		(a, b) = map(int, input().split())
		if b > a:
			(a, b) = (b, a)
		if a >= b:
			x = 0
			while b < a and a % 2 == 0:
				a = a // 2
				x += 1
			if b == a:
				print(x // 3 + 1 if x % 3 != 0 else x // 3)
			else:
				print(-1)
main()


from math import log2

def isPowerOfTwo(x):
	return x & x - 1 == 0
t = int(input())
for _ in range(t):
	(a, b) = [int(c) for c in input().split()]
	(a, b) = (min(a, b), max(a, b))
	if b % a != 0:
		print(-1)
	else:
		k = b // a
		if isPowerOfTwo(k):
			if k == 1:
				print(0)
			else:
				klog = int(log2(k))
				n3 = klog // 3
				n3dash = klog % 3
				n2 = n3dash // 2
				n2dash = n3dash % 2
				print(n2dash + n2 + n3)
		else:
			print(-1)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a < b:
		(a, b) = (b, a)
	cnt = 0
	while a > b:
		if a & 1:
			cnt = -1
			break
		cnt += 1
		a //= 2
	if cnt == -1 or a != b:
		print(-1)
		continue
	ans = cnt // 3
	cnt %= 3
	ans += cnt // 2
	cnt %= 2
	ans += cnt // 1
	cnt %= 1
	ans += cnt
	print(ans)


from sys import stdin, stdout

def get_int():
	return int(stdin.readline().strip())

def get_ints():
	return map(int, stdin.readline().strip().split())

def get_array():
	return list(map(int, stdin.readline().strip().split()))

def get_string():
	return stdin.readline().strip()
for _ in range(int(stdin.readline())):
	(a, b) = get_ints()
	if a == b:
		print(0)
		continue
	if a % b != 0 and b % a != 0:
		print(-1)
	else:
		c = 0
		while a != b:
			if a > b:
				if a % 8 == 0 and a // 8 >= b:
					a = a // 8
					c += 1
				elif a % 4 == 0 and a // 4 >= b:
					a = a // 4
					c += 1
				elif a % 2 == 0 and a // 2 >= b:
					a = a // 2
					c += 1
				else:
					print(-1)
					break
				if a == b:
					print(c)
					break
			else:
				if b % 8 == 0 and b // 8 >= a:
					b = b // 8
					c += 1
				elif b % 4 == 0 and b // 4 >= a:
					b = b // 4
					c += 1
				elif b % 2 == 0 and b // 2 >= a:
					b = b // 2
					c += 1
				else:
					print(-1)
					break
				if a == b:
					print(c)
					break


from math import gcd
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a % b == 0 or b % a == 0:
		c = max(a, b) // min(a, b)
		cc = 0
		while c % 8 == 0:
			c //= 8
			cc += 1
		while c % 4 == 0:
			c //= 4
			cc += 1
		while c % 2 == 0:
			c //= 2
			cc += 1
		if c == 1:
			print(cc)
		else:
			print(-1)
	else:
		print(-1)


from math import *
from math import factorial as fact, comb as ncr
from bisect import bisect_left as bl
from bisect import bisect_right as br
from array import array
from collections import Counter as ctr
from collections import deque as dq
li = lambda : list(map(int, input().split()))
arr = lambda a: array('i', a)
bi = lambda n: bin(n).replace('0b', '')
yn = lambda f: print('NYOE S'[f::2])

def solve():
	for _ in range(int(input())):
		(a, b) = sorted(li())
		c = 0
		while a < b:
			a *= 8
			c += 1
		if a == b or a // 4 == b or a // 2 == b:
			print(c)
		else:
			print(-1)
solve()


import sys
from math import *
input = sys.stdin.buffer.readline
t = int(input())
while t:
	t -= 1
	(a, b) = map(int, input().split())
	c = int(min(a, b))
	d = int(max(a, b))
	count = 0
	while c < d:
		c *= 2
		count += 1
	if c == d:
		print(int(ceil(count / 3)))
	else:
		print('-1')


import math

def Divisors(n):
	l = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
		i = i + 1
	return l

def SieveOfEratosthenes(n):
	l = []
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n + 1):
		if prime[p]:
			l.append(p)
	return l

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(n)
	return l

def Factors(n):
	result = []
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if i == n / i:
				result.append(i)
			else:
				result.append(i)
				result.append(n // i)
	result.append(1)
	result.append(n)
	return result

def maxSubArraySum(a):
	max_so_far = 0
	max_ending_here = 0
	size = len(a)
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far

def main():
	(a, b) = list(map(int, input().split()))
	if a > b:
		c = a
		a = b
		b = c
	if a == b:
		print(0)
	else:
		c = 0
		f = 0
		ans = 0
		l = []
		while b > a:
			if b % 2 != 0 and b > a:
				f = 1
				break
			b = b // 2
			l.append(b)
			c += 1
		if f == 0 and a in l:
			s = 0
			s += c // 3
			c = c % 3
			s += c // 2
			c = c % 2
			s += c
			print(s)
		else:
			print(-1)
t = int(input())
for i in range(0, t):
	main()


for _ in range(0, int(input())):
	(a, b) = sorted(map(int, input().split()))
	v = b // a
	x = 0
	w = 3
	if b % a == 0 and v & v - 1 == 0:
		while v > 1:
			if v % 2 ** w == 0:
				v //= 2 ** w
				x += 1
			else:
				w -= 1
		print(x)
	else:
		print('-1')


tc = int(input())
for i in range(tc):
	(x, y) = map(int, input().split())
	if x < y:
		(x, y) = (y, x)
	count = 0
	while x > y:
		if x % 8 == 0 and x // 8 >= y:
			x = x // 8
			count += 1
		elif x % 4 == 0 and x // 4 >= y:
			x = x // 4
			count += 1
		elif x % 2 == 0 and x // 2 >= y:
			x = x // 2
			count += 1
		else:
			break
	if x == y:
		print(count)
	else:
		print(-1)


from sys import stdin, stdout
import sys
from math import *
for __ in range(int(input())):
	(x, y) = map(int, input().split())
	if x == y:
		print(0)
		continue
	elif x % 2 == 1 and y < x:
		print(-1)
	elif x < y and y % 2 == 1:
		print(-1)
	elif x < y:
		count = 0
		while x < y:
			if x * 8 <= y:
				count += 1
				x = x * 8
			elif x * 4 <= y:
				count += 1
				x = x * 4
			elif x * 2 <= y:
				count += 1
				x = x * 2
			else:
				break
		if x == y:
			print(count)
		else:
			print(-1)
	else:
		count = 0
		while x > y:
			if x % 8 == 0 and x // 8 >= y:
				x = x // 8
				count += 1
			elif x % 4 == 0 and x // 4 >= y:
				x = x // 4
				count += 1
			elif x % 2 == 0 and x // 2 >= y:
				x = x // 2
				count += 1
			else:
				break
		if x == y:
			print(count)
		else:
			print(-1)


q = int(input())
for z in range(q):
	(a, b) = map(int, input().split(' '))
	if a == b:
		print(0)
	else:
		if a > b:
			(a, b) = (b, a)
		r = 0
		while a * 8 <= b:
			a *= 8
			r += 1
		while a * 4 <= b:
			a *= 4
			r += 1
		while a * 2 <= b:
			a *= 2
			r += 1
		if a == b:
			print(r)
		else:
			print(-1)


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
import random
from queue import PriorityQueue
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
from itertools import permutations
from math import factorial as f

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
import sys
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	elif b > a:
		cnt = 0
		while b != a and b > a:
			a *= 2
			cnt += 1
		if a != b:
			print(-1)
			continue
		k1 = cnt - 3 * (cnt // 3)
		k2 = k1 - 2 * (k1 // 2)
		print(k2 + cnt // 3 + k1 // 2)
	else:
		cnt = 0
		while b != a:
			if a % 2 != 0:
				break
			a //= 2
			cnt += 1
		if a != b:
			print(-1)
			continue
		k1 = cnt - 3 * (cnt // 3)
		k2 = k1 - 2 * (k1 // 2)
		print(k2 + cnt // 3 + k1 // 2)


from math import sqrt, log
for t in range(int(input())):
	(a, b) = map(int, input().split())
	k1 = 0
	k2 = 0
	if a < b:
		(a, b) = (b, a)
	for i in range(int(log(a, 2)), -1, -1):
		c = 2 ** i
		if a % c == 0 and k1 == 0:
			k1 = i
			a //= c
		if b % c == 0 and k2 == 0:
			k2 = i
			b //= c
		if k1 != 0 and k2 != 0:
			break
	if a != b:
		print(-1)
	elif k1 == k2:
		print(0)
	else:
		f = abs(k1 - k2)
		kl = f // 3
		f %= 3
		kl += f // 2
		f %= 2
		kl += f
		print(kl)


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
		continue
	if a > b:
		(a, b) = (b, a)
	c = 0
	while True:
		if a << 3 <= b:
			a = a << 3
			c += 1
		else:
			break
	while True:
		if a << 2 <= b:
			a = a << 2
			c += 1
		else:
			break
	while True:
		if a << 1 <= b:
			a = a << 1
			c += 1
		else:
			break
	if a == b:
		print(c)
	else:
		print(-1)


t = int(input())

def getBin(n):
	return bin(n)[2:]
while t > 0:
	l = [int(x) for x in input().split()]
	a = min(l[0], l[1])
	b = l[0] + l[1] - a
	cnt = 0
	while a < b:
		a = a * 2
		cnt += 1
	if a == b:
		ans = cnt // 3
		if cnt % 3 != 0:
			ans += 1
		print(ans)
	else:
		print(-1)
	t -= 1


def fun(a, b):
	if (a, b) in mem:
		return mem[a, b]
	if a == b:
		return 0
	elif a < b:
		return float('inf')
	else:
		x = fun(a // 2, b) if a % 2 == 0 else float('inf')
		y = fun(a // 4, b) if a % 4 == 0 else float('inf')
		z = fun(a // 8, b) if a % 8 == 0 else float('inf')
		mem[a, b] = 1 + min(x, y, z)
		return mem[a, b]
I = lambda : list(map(int, input().split(' ')))
global mem
for _ in range(I()[0]):
	(a, b) = I()
	mem = {}
	if a > b:
		x = fun(a, b)
	elif b > a:
		x = fun(b, a)
	else:
		x = 0
	if x == float('inf'):
		print(-1)
	else:
		print(x)


import math
t = int(input())
for _ in range(t):
	(a, b) = list(map(int, input().split()))
	if a > b:
		(a, b) = (b, a)
	if a == b:
		print(0)
	elif b % a == 0:
		k = b // a
		x = math.log2(k)
		if 2 ** int(x) == k:
			print(math.ceil(x / 3))
		else:
			print(-1)
	else:
		print(-1)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	larger = max(a, b)
	smaller = min(a, b)
	count = 0
	failed = False
	while smaller < larger:
		smaller *= 2
		count += 1
		if smaller > larger:
			failed = True
	if failed:
		print(-1)
	elif count % 3 == 0:
		print(count // 3)
	else:
		print(count // 3 + 1)


import sys

def input():
	return sys.stdin.readline()[:-1]

def main():
	for _ in range(int(input())):
		(a, b) = map(int, input().split())
		if a == b:
			print(0)
		elif a > b:
			ans = 0
			while a > b:
				if a % 2 == 0:
					a //= 2
					ans += 1
				else:
					break
			if a == b:
				s = ans // 3
				t = (ans - 3 * s) // 2
				u = ans - s * 3 - t * 2
				print(s + t + u)
			else:
				print(-1)
		else:
			ans = 0
			while a < b:
				a *= 2
				ans += 1
			if a == b:
				s = ans // 3
				t = (ans - 3 * s) // 2
				u = ans - s * 3 - t * 2
				print(s + t + u)
			else:
				print(-1)
main()


import math
from math import log2
t = int(input())
for j in range(t):
	ans = 0
	(a, b) = map(int, input().split())
	if a < b:
		(a, b) = (b, a)
	while b < a:
		ans += 1
		b *= 2
	if a == b:
		print(math.ceil(ans / 3))
	else:
		print(-1)


def main():
	NIN = lambda : int(input())
	SIN = lambda : map(int, input().split())
	LIN = lambda : list(map(int, input().split()))
	t = NIN()
	for _ in range(t):
		(a, b) = SIN()
		if a <= b:
			cnt = 0
			while a < b:
				a *= 2
				cnt += 1
			if a == b:
				print(cnt // 3 + (1 if cnt % 3 else 0))
			else:
				print(-1)
		else:
			cnt = 0
			while a > b:
				if a % 2 == 0:
					cnt += 1
					a //= 2
				else:
					break
			if a == b:
				print(cnt // 3 + (1 if cnt % 3 else 0))
			else:
				print(-1)
	return
main()


from collections import deque
from sys import stdin, stdout
import math
input = stdin.readline
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	cnt = 0
	while a < b:
		if a * 8 <= b:
			cnt += 1
			a *= 8
		elif a * 4 <= b:
			cnt += 1
			a *= 4
		else:
			cnt += 1
			a *= 2
	if a == b:
		print(cnt)
	else:
		print(-1)


def _input():
	return map(int, input().split())
for _ in range(int(input())):
	(a, b) = _input()
	res = 0
	if a % b == 0 or b % a == 0:
		res = 0
		t = a // b if a >= b else b // a
		while t % 8 == 0:
			t //= 8
			res += 1
		while t % 4 == 0:
			t //= 4
			res += 1
		while t % 2 == 0:
			t //= 2
			res += 1
	if a == b:
		print(0)
	elif res == 0 or t != 1:
		print(-1)
	else:
		print(res)


import sys
import math
t = int(sys.stdin.readline())
for i in range(t):
	(a, b) = map(int, sys.stdin.readline().strip().split())
	c = 0
	k = 0
	if a == b:
		print(0)
		continue
	if b > a:
		(a, b) = (b, a)
	if a > b:
		while b * 8 <= a:
			c += 1
			b *= 8
		while b * 4 <= a:
			c += 1
			b *= 4
		while b * 2 <= a:
			c += 1
			b *= 2
	if a == b:
		print(c)
	else:
		print(-1)


def low_bit(x):
	return x & -x

def solve(a, b):
	lb_b = low_bit(b)
	pre_b = b // lb_b
	right_move = 0
	left_move = 0
	while a > pre_b:
		if a // low_bit(a) == pre_b or a % 2 != 0:
			break
		a >>= 1
		right_move += 1
	if a // low_bit(a) != pre_b:
		return -1
	while a != b:
		if a < b:
			a <<= 1
			left_move += 1
		else:
			a >>= 1
			right_move += 1
	return (left_move + 2) // 3 + (right_move + 2) // 3
t = int(input())
for _ in range(t):
	(a, b) = [int(x) for x in input().split()]
	print(solve(a, b))


import sys
input = sys.stdin.readline
test = int(input())
while test != 0:
	test -= 1
	(a, b) = map(int, input().split())
	if a < b:
		te = b
		b = a
		a = te
	fl = False
	cnt = 0
	while fl == False:
		if a % 2 == 0 and a // 2 == b:
			cnt += 1
			break
		if a % 4 == 0 and a // 4 == b:
			cnt += 1
			break
		if a % 8 == 0 and a // 8 == b:
			cnt += 1
			break
		if a > b:
			if a % 8 == 0:
				a = a // 8
				cnt += 1
			elif a % 4 == 0:
				a = a // 4
				cnt += 1
			elif a % 2 == 0:
				a = a // 2
				cnt += 1
			else:
				fl = True
		elif a == b:
			break
		else:
			fl = True
	if fl:
		print(-1)
	else:
		print(cnt)


t = int(input())
while t:
	t -= 1
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	if a > b:
		(a, b) = (b, a)
	counter = 0
	while a < b:
		if a * 8 <= b:
			a *= 8
		elif a * 4 <= b:
			a *= 4
		else:
			a *= 2
		counter += 1
	if a == b:
		print(counter)
	else:
		print(-1)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a < b:
		(a, b) = (b, a)
	if a == b:
		print(0)
	elif a % b != 0:
		print(-1)
	else:
		temp = a // b
		ans = 0
		while temp % 8 == 0:
			ans += 1
			temp /= 8
			b *= 8
		while temp % 4 == 0:
			ans += 1
			temp /= 4
			b *= 4
		while temp % 2 == 0:
			ans += 1
			temp /= 2
			b *= 2
		if a == b:
			print(ans)
		else:
			print(-1)


import math

def shift_operations():
	q = int(input())
	for _ in range(q):
		(a, b) = map(int, input().split())
		if a == b:
			print(0)
			continue
		if a < b:
			(a, b) = (b, a)
		if a % b != 0:
			print(-1)
			continue
		numshifts = 0
		while a > b and a & 1 != 1:
			numshifts += 1
			a >>= 1
		if a != b:
			print(-1)
		else:
			print(math.ceil(numshifts / 3))
shift_operations()


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	ab = bin(a)[2:]
	bb = bin(b)[2:]
	if ab != bb[:len(ab)]:
		print(-1)
	elif bb[len(ab):].count('0') != len(bb[len(ab):]):
		print(-1)
	else:
		print((len(bb[len(ab):]) + 2) // 3)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	elif a > b:
		flag = 1
		count = 0
		while a >= b:
			if a == b:
				break
			if a % 2 != 0:
				flag = 0
				break
			else:
				count += 1
				a = a // 2
		if flag == 0 or a != b:
			print(-1)
		else:
			n = count
			ei = n // 3
			n = n - ei * 3
			fo = n // 2
			n = n - fo * 2
			print(ei + n + fo)
	else:
		flag = 1
		count = 0
		while a <= b:
			if a == b:
				break
			else:
				count += 1
				a = a * 2
		if flag == 0 or a != b:
			print(-1)
		else:
			n = count
			ei = n // 3
			n = n - ei * 3
			fo = n // 2
			n = n - fo * 2
			print(ei + n + fo)


def decimalToBinary(n):
	return bin(n).replace('0b', '')
t = int(input())
for i in range(t):
	(x, y) = map(int, input().split())
	y = str(decimalToBinary(y))
	x = str(decimalToBinary(x))
	j = len(max(x, y))
	k = len(min(x, y))
	count = 0
	count1 = 0
	if y > x:
		while True:
			if y[j - 1] == '0':
				count += 1
				j -= 1
			else:
				break
			if x[k - 1] == '0':
				count1 += 1
				k -= 1
		if x[:k] == y[:j]:
			if (count - count1) % 3 == 0:
				print(int((count - count1) / 3))
			else:
				print(int((count - count1) / 3) + 1)
		else:
			print(-1)
	else:
		while True:
			if x[j - 1] == '0':
				count += 1
				j -= 1
			else:
				break
			if y[k - 1] == '0':
				count1 += 1
				k -= 1
		if x[:j] == y[:k]:
			if (count - count1) % 3 == 0:
				print(int((count - count1) / 3))
			else:
				print(int((count - count1) / 3) + 1)
		else:
			print(-1)


p2 = {1 << i: i for i in range(64)}
for _ in range(int(input())):
	(a, b) = sorted(map(int, input().split()))
	(q, r) = divmod(b, a)
	if r != 0 or q not in p2:
		print(-1)
	else:
		v = p2[q]
		if v % 3 == 0:
			print(v // 3)
		else:
			print(v // 3 + 1)


import sys
import math
from sys import stdin, stdout

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()

def main():

	def minimumSteps(a, b):
		c = 0
		z = 0
		while a <= b:
			if a * 8 <= b:
				a = a * 8
				c += 1
			elif a * 4 <= b:
				a = a * 4
				c += 1
			elif a * 2 <= b:
				a *= 2
				c += 1
			elif a == b:
				break
			else:
				z = 1
				break
		if z == 1:
			return -1
		else:
			return c
	for t in range(int(input())):
		(a, b) = get_ints()
		if a == b:
			print(0)
		else:
			if a > b:
				(a, b) = (b, a)
			print(minimumSteps(a, b))
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	if n == m:
		print(0)
		continue
	if n > m:
		(n, m) = (m, n)
	count = 0
	ans = 0
	while n != m and n < m:
		n = n << 1
		count += 1
		if count == 3:
			ans += 1
			count = 0
	if n != m:
		print(-1)
		continue
	if count > 0:
		ans += 1
	print(ans)


tests = int(input())
for i in range(tests):
	line = list(map(int, input().split()))
	value = line[0]
	target = line[1]
	op2 = 0
	if target - value > 0:
		while target > value:
			value *= 2
			op2 += 1
	else:
		while target - value < 0 and value % 2 == 0:
			value = value // 2
			op2 += 1
	if target - value != 0:
		print(-1)
	else:
		operations = op2 // 3 + (op2 % 3 != 0)
		print(operations)


import math
t = int(input())
for tt in range(t):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	else:
		if a < b:
			temp = a
			a = b
			b = temp
		if a % b != 0:
			print(-1)
		else:
			xx = a // b
			yy = xx & xx - 1
			if yy == 0:
				temp = xx
				cc = 0
				while temp > 0:
					if temp % 8 == 0:
						temp //= 8
					elif temp % 4 == 0:
						temp //= 4
					elif temp % 2 == 0:
						temp //= 2
					else:
						break
					cc += 1
				print(cc)
			else:
				print(-1)


T = int(input())
for _ in range(T):
	(a, b) = [int(i) for i in input().split()]
	if a < b:
		(a, b) = (b, a)
	if a == b:
		print(0)
	elif a > b:
		if a % b:
			print('-1')
		else:
			q = a // b
			tmp = 1
			ind = 0
			while tmp < q:
				tmp *= 2
				ind += 1
			if tmp == q:
				ans = ind // 3
				if ind % 3:
					ans += 1
				print(ans)
			else:
				print(-1)


def f(n):
	while n % 2 == 0:
		n //= 2
	return n
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if f(a) != f(b):
		print(-1)
	else:
		if b > a:
			a = a + b
			b = a - b
			a = a - b
		a //= b
		ans = 0
		while a >= 8:
			a //= 8
			ans += 1
		if a > 1:
			ans += 1
		print(ans)


def hhh(n, k):
	c = 0
	while n > k and n % 2 == 0:
		n = n // 2
		c += 1
	if n == k:
		d = c // 3
		if c % 3 != 0:
			d += 1
		return d
	return -1
for t in range(int(input())):
	(a, b) = map(int, input().split())
	if a % b != 0:
		if b % a != 0:
			print('-1')
		else:
			print(hhh(b, a))
	else:
		print(hhh(a, b))


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	(a, b) = map(int, sys.stdin.readline().split())
	possible = True
	bina = '{0:b}'.format(a)
	binb = '{0:b}'.format(b)
	j = 0
	for i in range(min(len(bina), len(binb))):
		if bina[i] != binb[i]:
			possible = False
			break
		j += 1
	zeros = 0
	if a > b:
		while j < len(bina):
			if bina[j] != '0':
				possible = False
				break
			j += 1
			zeros += 1
	else:
		while j < len(binb):
			if binb[j] != '0':
				possible = False
				break
			j += 1
			zeros += 1
	if possible:
		ops = 0
		while zeros > 0:
			if zeros > 3:
				ops += zeros // 3
				zeros %= 3
			else:
				zeros = 0
				ops += 1
		print(ops)
	else:
		print(-1)


import sys
from math import log2 as log
input = sys.stdin.buffer.readline

def I():
	return list(map(int, input().split()))

def sieve(n):
	a = [1] * n
	for i in range(2, n):
		if a[i]:
			for j in range(i * i, n, i):
				a[j] = 0
	return a
for __ in range(int(input())):
	(a, b) = I()
	(b, a) = (max(a, b), min(a, b))
	if b % a != 0:
		print(-1)
		continue
	x = log(b // a)
	if b // a != 2 ** int(x):
		print(-1)
		continue
	else:
		x = int(x)
		m = 0
		m += x // 3
		x %= 3
		m += x // 2
		x %= 2
		m += x
		print(m)


import math
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	(x, y) = (min(a, b), max(a, b))
	if x == y:
		print(0)
	elif y % x != 0:
		print(-1)
	else:
		k = 0
		t = y // x
		dp = {}
		i = 0
		while 2 ** i < 10 ** 18:
			i += 1
			j = 2 ** i
			count = 0
			while j > 1:
				if j % 8 == 0:
					count += 1
					j = j // 8
				elif j % 4 == 0:
					count += 1
					j = j // 4
				elif j % 2 == 0:
					count += 1
					j = j // 2
			dp[2 ** i] = count
		if dp.get(t):
			print(dp[t])
		else:
			print(-1)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(l()[0]):
	(a, b) = l()
	x = a
	y = b
	while x % 2 == 0:
		x //= 2
	while y % 2 == 0:
		y //= 2
	if x != y:
		print(-1)
		continue
	if a > b:
		(a, b) = (b, a)
	k = b // a
	while k % 2 == 0:
		k //= 2
	if k != 1:
		print(-1)
	else:
		k = 0
		while a * 8 <= b:
			k += 1
			a *= 8
		while a * 4 <= b:
			k += 1
			a *= 4
		while a * 2 <= b:
			k += 1
			a *= 4
		print(k)


from decimal import *
for _ in range(int(input())):
	(a, b) = [int(num) for num in input().split()]
	k = 0
	shit = 0
	if a > b:
		k = Decimal(a) / Decimal(b)
	else:
		k = Decimal(b) / Decimal(a)
	if k % 1 != 0:
		print(-1)
	else:
		counter = 0
		while k != 1:
			if k % 2 == 0:
				k //= 2
				counter += 1
			else:
				counter = -1
				break
		if counter == -1:
			print(counter)
		elif counter % 3 == 0:
			print(counter // 3)
		else:
			print(counter // 3 + 1)


import math
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	if b % a != 0:
		print(-1)
		continue
	c = b // a
	cnt = 0
	while c % 2 == 0:
		c //= 2
		cnt += 1
	if c != 1:
		print(-1)
		continue
	else:
		print(math.ceil(cnt / 3))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	(a, b) = (max(a, b), min(a, b))
	(w, r) = (0, 0)
	if a == b:
		print(0)
	else:
		q = a // b
		if a % b == 0 and q % 2 == 0:
			while q > 1:
				if q % 8 == 0:
					w += 1
					q //= 8
				elif q % 4 == 0:
					w += 1
					q //= 4
				elif q % 2 == 0:
					w += 1
					q //= 2
				else:
					r = 1
					break
			if r == 1:
				print(-1)
			else:
				print(w)
		else:
			print(-1)


def solve():
	[a, b] = [int(x) for x in input().split()]
	if a == b:
		return 0
	if a < b:
		small = a
		big = b
	else:
		small = b
		big = a
	diff = len(bin(big).replace('0b', '')) - len(bin(small).replace('0b', ''))
	if small << diff == big:
		count = 0
		while diff > 0:
			if diff >= 3:
				diff -= 3
				count += 1
			elif diff >= 2:
				diff -= 2
				count += 1
			elif diff >= 1:
				diff -= 1
				count += 1
		return count
	else:
		return -1

def main():
	t = int(input())
	while t > 0:
		ans = solve()
		print(ans)
		t -= 1
main()


for s in [*open(0)][1:]:
	(a, b) = sorted(map(int, s.split()))
	x = 0
	while a < b:
		a *= 2
		x += 1
	print(-1 if a > b else (x + 2) // 3)


import sys

def solve(a, b):
	ls1a = a & -a
	ls1b = b & -b
	nop = 0
	rshift = 0
	lshift = 0
	if ls1a > ls1b:
		while ls1a > ls1b:
			rshift += 1
			ls1a >>= 1
		nop = (rshift + 2) // 3
		a2 = a >> rshift
	elif ls1a < ls1b:
		while ls1b > ls1a:
			lshift += 1
			ls1a <<= 1
		nop = (lshift + 2) // 3
		a2 = a << lshift
	else:
		return 0 if a == b else -1
	return nop if a2 == b else -1
IN = [x.strip() for x in sys.stdin.readlines()]
T = int(IN[0])
for i in range(T):
	(a, b) = [int(x) for x in IN[1 + i].split(' ')]
	result = solve(a, b)
	print(result)


for _ in range(int(input())):
	(a, b) = list(map(int, input().split()))
	(a, b) = (f'{a:b}', f'{b:b}')
	if len(a) > len(b):
		if a != b + '0' * (len(a) - len(b)):
			print(-1)
			continue
	elif b != a + '0' * (len(b) - len(a)):
		print(-1)
		continue
	len_diff = max(len(b) - len(a), len(a) - len(b))
	l2c = len_diff
	c3 = int(l2c / 3)
	l2c -= c3 * 3
	c2 = int(l2c / 2)
	l2c -= c2 * 2
	c1 = l2c
	print(c1 + c2 + c3)


import math
T = int(input())
for _ in range(T):
	(a, b) = list(map(int, input().split()))
	count = 0
	flag = 0
	mx = max(a, b)
	mn = min(a, b)
	if a > b:
		(a, b) = (b, a)
	count = 0
	while b > a:
		a = a * 2
		count += 1
	if a != b:
		print(-1)
	else:
		print(math.ceil(count / 3))


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	(a, b) = (max(a, b), min(a, b))
	if a == b:
		print(0)
	else:
		i = 1
		while a % 8 ** i == 0 and a // 8 ** i >= b:
			i += 1
		i -= 1
		counta = i
		a = a // 8 ** i
		if a % 4 == 0 and a // 4 >= b:
			a = a // 4
			counta += 1
		if a % 2 == 0 and a // 2 >= b:
			a = a // 2
			counta += 1
		if a == b:
			print(counta)
		else:
			print(-1)


from sys import stdin, stdout

def is_power_of_two(n):
	return n != 0 and n & n - 1 == 0
t = int(stdin.readline())
for _ in range(t):
	(a, b) = map(int, stdin.readline().split())
	if a < b:
		(a, b) = (b, a)
	if a % b != 0:
		print(-1)
		continue
	d = a // b
	if not is_power_of_two(d):
		print(-1)
		continue
	c = 0
	while d > 1:
		d //= 2
		c += 1
	if c % 3 == 0:
		print(c // 3)
	else:
		print(c // 3 + 1)


t = int(input())
for i in range(t):
	(a, b) = [int(x) for x in input().split()]
	c = 0
	while True:
		if a == b:
			print(c)
			break
		elif a < b:
			if a * 8 <= b:
				c += 1
				a = a * 8
			elif a * 4 <= b:
				c += 1
				a = a * 4
			elif a * 2 == b:
				c += 1
				a = a * 2
			else:
				print(-1)
				break
		elif b * 8 <= a:
			c += 1
			b = b * 8
		elif b * 4 <= a:
			c += 1
			b = b * 4
		elif b * 2 == a:
			c += 1
			b = b * 2
		else:
			print(-1)
			break


from math import log, ceil

def getR(a):
	while a % 2 == 0:
		a //= 2
	return a
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if getR(a) != getR(b):
		print(-1)
	else:
		(a, b) = (min(a, b), max(a, b))
		b //= a
		p = int(log(b) / log(2))
		print(ceil(p / 3))


for tc in range(int(input())):
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	answer = 0
	while a < b:
		if 8 * a <= b:
			a *= 8
		elif 4 * a <= b:
			a *= 4
		elif 2 * a <= b:
			a *= 2
		else:
			print(-1)
			break
		answer += 1
	if a == b:
		print(answer)


def func(n, m):
	i = 0
	count1 = 0
	count2 = 0
	if n == m:
		return 0
	k1 = min(n, m)
	k2 = max(n, m)
	if k1 == k2:
		return 0
	if k2 % k1 != 0:
		return -1
	while k1 < k2:
		i += 1
		k1 = 2 * k1
		if k1 > k2:
			return -1
	if i % 3 == 0:
		return int(i / 3)
	else:
		return int(i / 3) + 1
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	print(func(n, m))


import sys
input = sys.stdin.readline
import math
for _ in range(int(input())):
	(a, b) = sorted(map(int, input().split()))
	x = math.log2(b / a)
	if math.log2(b / a).is_integer():
		if a * int(2 ** x) != b:
			print(-1)
		else:
			print(int(x // 3 + (x % 3 > 0)))
	else:
		print(-1)


def solve(a, b, arr):
	if b == a:
		return 1
	if b < a:
		if a % 2 == 1:
			return -1
		elif a // b == 1:
			return -1
		else:
			arr.append(2)
			return solve(a // 2, b, arr)
	if a < b:
		if b % 2 == 1:
			return -1
		elif b // a == 1:
			return -1
		else:
			arr.append(2)
			return solve(a * 2, b, arr)
n = int(input())
while n:
	(p, q) = map(int, input().split())
	arr = []
	ans = solve(p, q, arr)
	x = len(arr)
	if ans == 1:
		print(x // 3 + x % 3 // 2 + x % 3 % 2)
	else:
		print(-1)
	n = n - 1


import sys
from os import path
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
get_int = lambda : int(input())
get_ints = lambda : map(int, input().split())
get_ints_list = lambda : list(get_ints())
import math
t = get_int()
for _ in range(t):
	(a, b) = get_ints()
	if a > b:
		(a, b) = (b, a)
	ans = 0
	cnt = 0
	while a < b:
		a *= 2
		cnt += 1
	if a != b:
		print(-1)
		continue
	x = cnt // 3
	cnt %= 3
	y = cnt // 2
	cnt %= 2
	z = cnt
	print(x + y + z)


r = int(input())
results = []
for i in range(r):
	z = input().split(' ')
	a = int(z[0])
	b = int(z[1])
	if a == b:
		results.append(0)
		continue
	else:
		if b > a:
			(b, a) = (a, b)
		count = 0
		while a > b:
			if a % 8 == 0 and a // 8 >= b:
				a = a // 8
				count += 1
			elif a % 4 == 0 and a // 4 >= b:
				a = a // 4
				count += 1
			elif a % 2 == 0 and a // 2 >= b:
				a = a // 2
				count += 1
			elif a != b:
				count = -1
				break
			else:
				break
		results.append(count)
for x in results:
	print(int(x))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	l = [8, 4, 2]
	if a == b:
		print('0')
	elif a < b:
		count = 0
		fg = 0
		for i in range(3):
			while a < b:
				a = a * l[i]
				count += 1
			if a == b:
				print(count)
				fg = 1
				break
			else:
				a = a // l[i]
				count -= 1
		if fg == 0:
			print('-1')
	elif a > b:
		(count, fg, fg1) = (0, 0, 0)
		for i in range(3):
			while a > b and a % l[i] == 0:
				a = a // l[i]
				count += 1
				fg1 = 1
			if a == b and fg1 == 1:
				print(count)
				fg = 1
				fg1 = 0
				break
			elif a > b and fg1 == 1:
				fg1 = 0
			elif a < b and fg1 == 1:
				a = a * l[i]
				count -= 1
				fg1 = 0
		if fg == 0:
			print('-1')


import sys, collections, math

def calc(a, b):
	big = max(a, b)
	small = min(a, b)
	if big == small:
		return 0
	if big % small != 0:
		return -1
	temp = big // small
	exp = 0
	can = True
	while temp > 1:
		if temp % 2 != 0:
			can = False
			break
		temp //= 2
		exp += 1
	if can:
		eight = exp // 3
		exp %= 3
		four = exp // 2
		exp %= 2
		return eight + four + exp
	else:
		return -1
tc = int(sys.stdin.readline())
for _ in range(tc):
	(a, b) = map(int, sys.stdin.readline().split())
	print(calc(a, b))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	coun = 0
	f = 0
	while a != b:
		if a < b:
			if a * 8 <= b:
				a = a * 8
				coun += 1
				continue
			if a * 4 <= b:
				a = a * 4
				coun += 1
				continue
			if a * 2 <= b:
				a = a * 2
				coun += 1
				continue
			else:
				f = 1
				break
		if a > b:
			if a % 8 == 0 and a // 8 >= b:
				a = a // 8
				coun += 1
				continue
			if a % 4 == 0 and a // 4 >= b:
				a = a // 4
				coun += 1
				continue
			if a % 2 == 0 and a // 2 >= b:
				a = a // 2
				coun += 1
				continue
			else:
				f = 1
				break
	if f == 1:
		print('-1')
	else:
		print(coun)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	(a, b) = (max(a, b), min(a, b))
	if a % b != 0:
		print(-1)
	else:
		n = a // b
		s = 0
		while n % 2 == 0:
			s += 1
			n = n // 2
		if n > 1:
			print(-1)
		else:
			ans = s // 3
			if s % 3 > 0:
				ans += 1
			print(ans)


from math import ceil
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	(x1, y1) = (x, y)
	cnt1 = 0
	cnt2 = 0
	while x1 & 1 == 0:
		x1 >>= 1
		cnt1 += 1
	while y1 & 1 == 0:
		y1 >>= 1
		cnt2 += 1
	if x1 != y1:
		print(-1)
		continue
	print(ceil(abs(cnt1 - cnt2) / 3))


def mult(zahl1, zahl2):
	counter = 0
	while zahl1 > zahl2:
		zahl2 = zahl2 * 2
		counter += 1
		if zahl2 == zahl1:
			break
		if zahl2 > zahl1:
			return -1
	back = 0
	while counter > 4 or counter == 3:
		counter = counter - 3
		back += 1
		if counter == 0:
			return back
	while counter > 1:
		counter = counter - 2
		back += 1
		if counter == 0:
			return back
	if counter == 1:
		back += 1
		return back
puffer1 = 0
puffer2 = 0
ergebnis = 0
A = []
n = int(input())
for i in range(n):
	A.append(input().split(' '))
for i in range(n):
	for a in range(len(A[i])):
		A[i][a] = int(A[i][a])
for i in range(n):
	for a in range(len(A[i])):
		puffer1 = A[i][0]
		puffer2 = A[i][1]
	if puffer1 > puffer2:
		ergebnis = mult(puffer1, puffer2)
		A[i] = ergebnis
	elif puffer1 == puffer2:
		A[i] = 0
	else:
		ergebnis = mult(puffer2, puffer1)
		A[i] = ergebnis
for i in A:
	print(i)


t = int(input())
for _ in range(t):
	(a, b) = [int(r) for r in input().split()]
	if a == b:
		print(0)
		continue
	if a > b:
		ans = 0
		j = 0
		while a != b and j < 100:
			j += 1
			if a // 8 >= b and a % 8 == 0:
				a //= 8
				ans += 1
			elif a // 4 >= b and a % 4 == 0:
				a //= 4
				ans += 1
			elif a // 2 >= b and a % 2 == 0:
				a //= 2
				ans += 1
		if a != b:
			print(-1)
		else:
			print(ans)
	else:
		ans = 0
		j = 0
		while a != b and j < 100:
			j += 1
			if a * 8 <= b:
				a *= 8
				ans += 1
			elif a * 4 <= b:
				a *= 4
				ans += 1
			elif a * 2 <= b:
				a *= 2
				ans += 1
		if a != b:
			print(-1)
		else:
			print(ans)


a = int(input())
for i in range(a):
	(x, y) = map(int, input().split())
	if y == x:
		print(0)
		continue
	(x, y) = (min(x, y), max(x, y))
	if y % x != 0:
		print(-1)
		continue
	else:
		temp = y // x
		count = 0
		while temp % 2 == 0 and temp > 0:
			count += 1
			temp = temp // 2
		if temp != 1:
			print(-1)
		else:
			ans = 0
			ans += count // 3
			count = count % 3
			ans += count // 2
			count = count % 2
			ans += count // 1
			print(ans)


import math
lis = []
for j in range(69):
	lis.append(2 ** j)
t = int(input())
for i in range(t):
	(a, b) = list(map(int, input().split()))
	if a == b:
		print(0)
	elif a > b:
		c = a % b
		if c != 0:
			print(-1)
		else:
			d = a // b
			s = -1
			for j in range(69):
				if lis[j] == d:
					s = j
			if s == -1:
				print(-1)
			else:
				x = s
				p = x // 3
				x = x - p * 3
				q = x // 2
				r = x - q * 2
				print(int(p + q + r))
	else:
		c = b % a
		if c != 0:
			print(-1)
		else:
			d = b // a
			s = -1
			for j in range(69):
				if lis[j] == d:
					s = j
			if s == -1:
				print(-1)
			else:
				x = s
				p = x // 3
				x = x - p * 3
				q = x // 2
				r = x - q * 2
				print(int(p + q + r))


t = int(input())
while t > 0:
	t -= 1
	(a, b) = map(int, input().split(' '))
	if a == b:
		print(0)
	elif a // b < 2 and a > b:
		print(-1)
	elif b // a < 2 and b > a:
		print(-1)
	else:
		flag = True
		op = 0
		if a < b:
			while a != b:
				if a * 8 <= b:
					a *= 8
					op += 1
				elif a * 4 <= b:
					a *= 4
					op += 1
				elif a * 2 <= b:
					a *= 2
					op += 1
				else:
					flag = False
					break
				if b // a < 2 and a != b:
					flag = False
					break
			if not flag:
				print(-1)
			else:
				print(op)
		elif a > b:
			while a != b:
				if a % 8 == 0 and a // 8 >= b:
					a = a // 8
					op += 1
				elif a % 4 == 0 and a // 4 >= b:
					a = a // 4
					op += 1
				elif a % 2 == 0 and a // 2 >= b:
					a = a // 2
					op += 1
				else:
					flag = False
					break
				if a // b < 2 and b != a:
					flag = False
					break
			if not flag:
				print(-1)
			else:
				print(op)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlist():
	return list(map(int, input().split()))

def instr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()

def getr(x):
	while x % 2 == 0:
		x = x // 2
	return x
for i in range(t):
	(a, b) = invr()
	if a > b:
		(a, b) = (b, a)
	if getr(a) != getr(b):
		print('-1')
	else:
		ans = 0
		b = b / a
		while b >= 8:
			(b, ans) = (b / 8, ans + 1)
		if b > 1:
			ans = ans + 1
		print(ans)


T = int(input())

def ans(a, b):
	if b < a:
		return ans(b, a)
	if a == b:
		return 0
	if 8 * a <= b:
		return 1 + ans(8 * a, b)
	if 4 * a <= b:
		return 1 + ans(4 * a, b)
	if 2 * a <= b:
		return 1 + ans(2 * a, b)
	return float('inf')
for t in range(T):
	(a, b) = input().split(' ')
	a = int(a)
	b = int(b)
	r = ans(a, b)
	if r == float('inf'):
		print(-1)
	else:
		print(r)


import math
t = int(input())
for i in range(t):
	(a, b) = list(map(int, input().split()))
	if a > b:
		(a, b) = (b, a)
	ans = 0
	while 8 * a <= b:
		a = a * 8
		ans += 1
	while 4 * a <= b:
		a = a * 4
		ans += 1
	while 2 * a <= b:
		ans += 1
		a = a * 2
	if a == b:
		print(ans)
	else:
		print(-1)


import math, sys
from sys import stdin, stdout
from collections import Counter, defaultdict, deque
input = stdin.readline
I = lambda : int(input())
li = lambda : list(map(int, input().split()))

def solve():
	(a, b) = li()
	k = 0
	while a < b:
		a *= 2
		k += 1
	if a == b:
		ans = 0
		ans += k // 3
		k %= 3
		ans += k // 2
		k %= 2
		ans += k
		print(ans)
		return
	k = 0
	while a > b and a % 2 == 0:
		a = a // 2
		k += 1
	if a == b:
		ans = 0
		ans += k // 3
		k %= 3
		ans += k // 2
		k %= 2
		ans += k
		print(ans)
	else:
		print(-1)
for _ in range(I()):
	solve()


def aa(n):
	nd = 0
	while n % 8 == 0:
		n = n // 8
		nd += 1
	while n % 4 == 0:
		n = n // 4
		nd += 1
	while n % 2 == 0:
		n = n // 2
		nd += 1
	if n == 1:
		return nd
	return -1
for _ in range(int(input())):
	(a, b) = [int(i) for i in input().split()]
	if a == b:
		print(0)
	elif a < b:
		if b % a == 0:
			c = b // a
			print(aa(c))
		else:
			print(-1)
	elif a % b == 0:
		c = a // b
		print(aa(c))
	else:
		print(-1)


import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = int(input())
while t:
	t -= 1
	(a, b) = [str(bin(int(x)))[2:] for x in input().split()]
	check = False
	if a.find(b) == 0 and a[len(b):].count('0') == len(a[len(b):]):
		check = True
	elif b.find(a) == 0 and b[len(a):].count('0') == len(b[len(a):]):
		check = True
	if check:
		print((abs(len(a) - len(b)) + 2) // 3)
	else:
		print(-1)


t = int(input())
for s in range(t):
	(a, b) = map(int, input().split())
	if b > a:
		temp = b
		b = a
		a = temp
	add = 0
	flag = 0
	while True:
		if b == a:
			flag = 0
			break
		elif b > a:
			flag = 1
			break
		b = b * 2
		add += 1
	if flag == 1:
		print(-1)
	else:
		a = add // 3
		aa = add % 3
		b = aa // 2
		bb = aa % 2
		c = bb // 1
		print(a + b + c)


from sys import stdin
for _ in range(int(stdin.readline())):
	res = 0
	(a, b) = sorted(map(int, stdin.readline().split()))
	if b % a != 0:
		print(-1)
		continue
	t = b // a
	while t % 8 == 0:
		t //= 8
		res += 1
	while t % 4 == 0:
		t //= 4
		res += 1
	while t % 2 == 0:
		t //= 2
		res += 1
	if t > 1:
		print(-1)
	else:
		print(res)


for _ in range(int(input())):
	(a1, b1) = map(int, input().split())
	a = min(a1, b1)
	b = max(a1, b1)
	if a == b:
		print(0)
	elif b % a == 0:
		k = b // a
		ans = 0
		while k >= 8 and k % 8 == 0:
			ans += 1
			k = k // 8
		while k >= 4 and k % 4 == 0:
			ans += 1
			k = k // 4
		while k >= 2 and k % 2 == 0:
			ans += 1
			k = k // 2
		if k != 1:
			print(-1)
		else:
			print(ans)
	else:
		print(-1)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split(' '))
	count_8 = 0
	count_4 = 0
	count_t = 0
	if a % b == 0 or b % a == 0:
		if a == b:
			print(0)
		elif a > b:
			q = a // b
			result = q & q - 1
			if result == 0:
				if q >= 8:
					while q >= 8:
						count_8 = count_8 + 1
						q = q / 8
				elif q >= 4:
					while q >= 4:
						count_4 = count_4 + 1
						q = q / 4
				if q >= 2:
					print(count_8 + count_4 + 1)
				else:
					print(count_8 + count_4)
			else:
				print(-1)
		elif a < b:
			q = b // a
			result = q & q - 1
			if result == 0:
				if q >= 8:
					while q >= 8:
						count_8 = count_8 + 1
						q = q / 8
				elif q >= 4:
					while q >= 4:
						count_4 = count_4 + 1
						q = q / 4
				if q >= 2:
					print(count_8 + count_4 + 1)
				else:
					print(count_8 + count_4)
			else:
				print(-1)
	else:
		print(-1)


import math
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	p = 0
	while a < b:
		if a * 8 <= b:
			a *= 8
			p += 1
		elif a * 4 <= b:
			a *= 4
			p += 1
		else:
			a *= 2
			p += 1
	if a == b:
		print(p)
	else:
		print(-1)


import math
t = int(input())
for _ in range(t):
	(a, b) = (int(var) for var in input().split())
	if a == b:
		print(0)
	elif (a % b == 0 or b % a == 0) and a != 0 and (b != 0):
		ways = max(a, b) // min(a, b)
		power = int(math.log2(ways))
		if ways == 2 ** power:
			delta = 1 if power % 3 > 0 else 0
			print(power // 3 + delta)
		else:
			print(-1)
	else:
		print(-1)


from sys import stdin
from math import gcd, sqrt
from collections import deque
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
hg = lambda x, y: (y + x - 1) // x * x
for _ in range(I()):
	(a, b) = R()
	if a > b:
		(a, b) = (b, a)
	if b % a:
		print(-1)
	else:
		ans = 0
		c = b // a
		while not c % 8:
			ans += 1
			c //= 8
		while not c % 4:
			ans += 1
			c //= 4
		while not c % 2:
			ans += 1
			c //= 2
		if ans == 0 and a != b or c != 1:
			print(-1)
		else:
			print(ans)


from sys import stdin, stdout
from math import ceil

def solve(a, b):
	x = max(a, b)
	y = min(a, b)
	c = 0
	while x != y:
		if x % 2:
			print(-1)
			return True
		c += 1
		x //= 2
	print(ceil(c / 3))
	return True
for _ in range(int(input())):
	(n, m) = map(int, stdin.readline().split())
	solve(n, m)


def find2(x):
	count = 0
	while not x & 1:
		count += 1
		x >>= 1
	return (count, x)
for _ in range(int(input())):
	(aa, bb) = map(int, input().split())
	if aa == bb:
		print(0)
		continue
	(ca, a) = find2(aa)
	(cb, b) = find2(bb)
	if a != b:
		print(-1)
		continue
	ca = abs(ca - cb)
	ans = 0
	ans += ca // 3
	ca -= 3 * (ca // 3)
	ans += ca // 2
	ca -= 2 * (ca // 2)
	ans += ca
	print(ans)


def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
		continue
	x = 0
	s = 0
	if a > b:
		while a != b:
			q = a
			a = a // 2
			if q % 2 != 0:
				s = -1
				break
			if a < 0:
				s = -1
				break
			x = x + 1
	else:
		if b % 2 != 0:
			print(-1)
			continue
		while a != b:
			a = a * 2
			x = x + 1
			if a > b:
				s = -1
				break
	if s == -1:
		print(-1)
		continue
	if x < 4:
		print(1)
	else:
		a = x // 3
		b = x % 3
		if x % 3 == 2:
			b = 1
		print(a + b)


for _ in range(int(input())):
	(x, y) = list(map(int, input().split()))
	a = min(x, y)
	b = max(x, y)
	x = bin(a)[2:]
	y = bin(b)[2:]
	n = len(x)
	m = len(y)
	c = 0
	if y.startswith(x) and y[n:] == '0' * (len(y) - n):
		n = len(y) - len(x)
		c += n // 3
		n = n % 3
		c += n // 2
		n = n % 2
		c += n
		print(c)
	else:
		print(-1)


t = int(input())
for i in range(t):
	(init, target) = input().split()
	init = int(init)
	target = int(target)
	mul = True
	loop = False
	count = 0
	operation = 0
	if init > target:
		(target, init) = (init, target)
		mul = False
	if init == target:
		print(0)
		continue
	if init < target:
		loop = True
	while True:
		init = init << 1
		count += 1
		if init > target:
			print(-1)
			break
		elif init == target:
			operation += int(count / 3)
			count = count % 3
			operation += int(count / 2)
			count = count % 2
			operation += count
			print(operation)
			break


import sys
from sys import stdin
import math
input = sys.stdin.readline
for _ in range(int(input())):
	(a, b) = [int(j) for j in input().split()]
	ans = 0
	if a == b:
		print(ans)
	elif a > b:
		if a % b != 0:
			print(-1)
		else:
			t = a // b
			flag = 0
			while t != 1:
				if t % 8 == 0:
					t = t // 8
					ans += 1
				elif t % 4 == 0:
					t = t // 4
					ans += 1
				elif t % 2 == 0:
					t = t // 2
					ans += 1
				else:
					flag = 1
					break
			if flag == 0:
				print(ans)
			else:
				print(-1)
	elif a < b:
		if b % a != 0:
			print(-1)
		else:
			t = b // a
			flag = 0
			while t != 1:
				if t % 8 == 0:
					t = t // 8
					ans += 1
				elif t % 4 == 0:
					t = t // 4
					ans += 1
				elif t % 2 == 0:
					t = t // 2
					ans += 1
				else:
					flag = 1
					break
			if flag == 0:
				print(ans)
			else:
				print(-1)


def fun(h):
	f = c = 0
	while h > 1:
		if h % 8 == 0:
			h = h // 8
		elif h % 4 == 0:
			h = h // 4
		elif h % 2 == 0:
			h = h // 2
		else:
			f = 1
			break
		c += 1
	if f == 1:
		return -1
	return c
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	elif a > b:
		if a % b != 0:
			print(-1)
		else:
			h = a // b
			print(fun(h))
	elif b % a != 0:
		print(-1)
	else:
		h = b // a
		print(fun(h))


def measure(n):
	sum = 0
	t = 0
	while 2 ** (t + 1) <= n:
		t += 1
	if 2 ** t == n:
		sum += t // 3
		t = t % 3
		sum += t // 2
		t = t % 2
		sum += t
		return sum
	else:
		return -1
for i in range(int(input())):
	l = list(map(int, input().rstrip().split()))
	a = l[0]
	b = l[1]
	if max(a, b) % min(b, a) == 0:
		x = measure(max(a, b) // min(b, a))
		print(x)
	else:
		print(-1)


import sys
lines = sys.stdin.read().strip().splitlines()[1:]

def power_of_two(n):
	i = 0
	while n != 1 and n % 2 == 0:
		n //= 2
		i += 1
	return (n == 1, i)
for l in lines:
	(a, b) = list(map(int, l.split()))
	if b > a:
		(a, b) = (b, a)
	if a % b != 0:
		print(-1)
		continue
	if a // b % 2 != 0 and a // b != 1:
		print(-1)
		continue
	(ok, d) = power_of_two(a // b)
	if not ok:
		print(-1)
		continue
	i = 0
	i += d // 3
	d -= d // 3 * 3
	i += d // 2
	d -= d // 2 * 2
	i += d
	print(i)


for i in range(int(input())):
	(a, b) = map(int, input().split())

	def fun1(n1, n2):
		c = 0
		while n1 != n2:
			if n1 % 8 == 0 and n1 // 8 >= n2:
				n1 = n1 // 8
				c += 1
			elif n1 % 4 == 0 and n1 // 4 >= n2:
				n1 = n1 // 4
				c += 1
			elif n1 % 2 == 0 and n1 // 2 >= n2:
				n1 = n1 // 2
				c += 1
			else:
				c = -1
				break
		return c
	if a == b:
		print(0)
	else:
		print(fun1(max(a, b), min(a, b)))


import sys
input = lambda : sys.stdin.readline().rstrip()
inp = sys.stdin.buffer.readline

def I():
	return list(map(int, inp().split()))
for _ in range(I()[0]):
	(a, b) = I()
	n1 = a
	n2 = b
	while not n1 & 1:
		n1 //= 2
	while not n2 & 1:
		n2 //= 2
	if n1 != n2:
		print(-1)
	else:
		if a < b:
			(a, b) = (b, a)
		num = a // b
		ans = 0
		while num != 0 and num % 2 == 0:
			if num % 8 == 0:
				num //= 8
				ans += 1
			elif num % 4 == 0:
				num //= 4
				ans += 1
			elif num % 2 == 0:
				num //= 2
				ans += 1
		print(ans)


def f(n, m):
	if n == m:
		return 0
	if n > m:
		if n % 8 == 0 and n // 8 >= m:
			p = f(n // 8, m)
			return -1 if -1 == p else 1 + p
		elif n % 4 == 0 and n // 4 >= m:
			p = f(n // 4, m)
			return -1 if -1 == p else 1 + p
		elif n % 2 == 0 and n // 2 >= m:
			p = f(n // 2, m)
			return -1 if -1 == p else 1 + p
		else:
			return -1
	elif n * 8 <= m:
		p = f(n * 8, m)
		return -1 if -1 == p else 1 + p
	elif n * 4 <= m:
		p = f(n * 4, m)
		return -1 if -1 == p else 1 + p
	elif n * 2 <= m:
		p = f(n * 2, m)
		return -1 if -1 == p else 1 + p
	else:
		return -1
t = int(input())
while t:
	t -= 1
	(n, m) = map(int, input().split())
	print(f(n, m))


from math import log2, ceil
for _ in range(int(input())):
	(a, b) = map(int, input().split(' '))
	(a, b) = (max(a, b), min(a, b))
	if a == b:
		print(0)
		continue
	a = bin(a)
	b = bin(b)
	if b in a:
		digits = a[len(b):]
		if digits.find('1') != -1:
			print(-1)
			continue
		print(ceil(len(digits) / 3))
	else:
		print(-1)


from math import sqrt
t = int(input())
for q in range(0, t):
	(a, b) = map(int, input().split())
	if a > b:
		tmp = a
		a = b
		b = tmp
	if a == b:
		print(0)
	elif b % a != 0:
		print(-1)
	else:
		k = b // a
		num = 0
		while k > 1:
			if k % 2 == 0:
				num += 1
				k = k // 2
			else:
				break
		if k != 1:
			print(-1)
		else:
			print(num // 3 + num % 3 // 2 + num % 3 % 2)


n1 = int(input())
for x in range(n1):
	s = input().split(' ')
	a = int(s[0])
	b = int(s[1])
	if a > b:
		(a, b) = (b, a)
	count = 0
	while a < b:
		count = count + 1
		a = a * 2
	if a == b:
		print(int(count / 3) + int(count % 3 != 0))
	else:
		print(-1)


import sys
for _ in range(int(sys.stdin.readline())):
	(x, y) = map(int, sys.stdin.readline().split())
	if x > y:
		(x, y) = (y, x)
	c = 0
	while x < y:
		c += 1
		x <<= 1
	if x == y:
		print(c // 3 + c % 3 // 2 + c % 3 % 2)
	else:
		print(-1)


def fix(x, y):
	if x % y != 0:
		print(-1)
		return
	j = x // y
	if j & j - 1 != 0:
		print(-1)
		return
	ans = 0
	while x > y:
		if x // 8 >= y:
			x //= 8
		elif x // 4 >= y:
			x //= 4
		else:
			x //= 2
		ans += 1
	print(ans)
for n in range(int(input())):
	(x, y) = map(int, input().split())
	if x == y:
		print(0)
		continue
	if x > y:
		fix(x, y)
	else:
		fix(y, x)


def solve(a, b):

	def helper(a, b):
		if a == b:
			return 0
		if a < b:
			return helper(b, a)
		result = 0
		while a > b:
			if a % 2:
				return -1
			else:
				a //= 2
				result += 1
			if a == b:
				return result
		return -1
	ans = helper(a, b)
	if ans == -1:
		return ans
	result = ans // 3
	ans %= 3
	result += ans // 2
	ans %= 2
	if ans:
		result += ans
	return result
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	result = solve(a, b)
	print(result)


for ____ in range(int(input())):
	(a, b) = map(int, input().split(' '))
	if a > b:
		(b, a) = (a, b)
	if b % a != 0:
		print(-1)
		continue
	c = b // a
	counter = 0
	while c % 8 == 0:
		counter += 1
		c //= 8
	if c % 2 == 0:
		counter += 1
		if c % 4 == 0:
			c //= 4
		else:
			c //= 2
	if c != 1:
		print(-1)
		continue
	else:
		print(counter)


import sys
from collections import defaultdict as dd
from queue import Queue
import math
import itertools
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	e = 0
	if k == n:
		print(0)
	elif k < n:
		while n % 2 == 0 and k < n:
			e += 1
			n //= 2
		if k == n:
			print(e // 3 + e % 3 // 2 + e % 3 % 2)
		else:
			print(-1)
	else:
		while n < k:
			n *= 2
			e += 1
		if n == k:
			print(e // 3 + e % 3 // 2 + e % 3 % 2)
		else:
			print(-1)


import math
for i in range(int(input())):
	(a, b) = map(int, input().split())
	if a > b:
		if a % b == 0:
			x = a // b
			if x and (not x & x - 1):
				d = int(math.log(x, 2))
				d8 = d // 3
				d = d - d8 * 3
				d4 = d // 2
				d = d - d4 * 2
				d2 = d
				print(d8 + d4 + d2)
			else:
				print(-1)
		else:
			print(-1)
	elif b > a:
		if b % a == 0:
			x = b // a
			if x and (not x & x - 1):
				d = int(math.log(x, 2))
				d8 = d // 3
				d = d - d8 * 3
				d4 = d // 2
				d = d - d4 * 2
				d2 = d
				print(d8 + d4 + d2)
			else:
				print(-1)
		else:
			print(-1)
	else:
		print(0)


import math
t = int(input())
while t > 0:
	(a, b) = [int(x) for x in input().split()]
	if a == b:
		print(0)
	elif (a % b == 0 or b % a == 0) and a != 0 and (b != 0):
		temp = max(a, b) // min(a, b)
		if temp == 2 ** int(math.log2(temp)):
			ans = int(math.log2(temp))
			if ans % 3 == 0:
				print(int(ans / 3))
			else:
				print(int(ans / 3) + 1)
		else:
			print(-1)
	else:
		print(-1)
	t -= 1


from math import ceil
for _ in range(int(input())):
	(r, s) = map(int, input().split())
	i = j = 0
	(rr, ss) = (r, s)
	while ss % 2 == 0:
		ss //= 2
		j += 1
	while rr % 2 == 0:
		rr //= 2
		i += 1
	if rr != ss:
		print(-1)
		continue
	print(ceil(abs(i - j) / 3))


def solve(case):
	initial_target = list(map(int, input().split()))
	greater = max(initial_target)
	smaller = min(initial_target)
	to_factorize = greater // smaller
	number_of_factorizations = 0
	if greater % smaller == 0:
		while to_factorize % 8 == 0:
			to_factorize = to_factorize // 8
			number_of_factorizations += 1
		if to_factorize in (2, 4):
			number_of_factorizations += 1
		elif to_factorize != 1:
			number_of_factorizations = -1
	else:
		number_of_factorizations = -1
	print(number_of_factorizations)

def main():
	for case in range(int(input())):
		solve(case)
main()


import sys
import math
import collections
from collections import deque
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def factors(n):
	return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))
T = 1
T = int(stdin.readline())
for _ in range(T):
	(a, b) = list(map(int, stdin.readline().split()))
	if a == b:
		print(0)
		continue
	if b % a == 0 or a % b == 0:
		if isPowerOfTwo(b // a) or isPowerOfTwo(a // b) % 2:
			if b > a:
				c = b // a
				m = int(math.log(c, 2))
				q = m // 3
				r = m % 3
				if r == 0:
					print(q)
				else:
					print(q + 1)
			else:
				c = a // b
				m = int(math.log(c, 2))
				q = m // 3
				r = m % 3
				if r == 0:
					print(q)
				else:
					print(q + 1)
		else:
			print(-1)
	else:
		print(-1)


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split(' '))
	if a == b:
		print(0)
	elif a > b:
		c = a // b
		num2 = 0
		while c % 2 == 0 and c != 0:
			c = c // 2
			num2 += 1
		if c != 1 or a % b != 0:
			print(-1)
		else:
			ans = 0
			ans += num2 // 3
			num2 = num2 % 3
			ans += num2 // 2
			num2 = num2 % 2
			ans += num2
			print(ans)
	elif a < b:
		c = b // a
		num2 = 0
		while c % 2 == 0 and c != 0:
			c = c // 2
			num2 += 1
		if c != 1 or b % a != 0:
			print(-1)
		else:
			ans = 0
			ans += num2 // 3
			num2 = num2 % 3
			ans += num2 // 2
			num2 = num2 % 2
			ans += num2
			print(ans)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if max(a, b) % min(a, b) != 0:
		print(-1)
	else:
		ar = [8, 4, 2]
		val = max(a, b) // min(a, b)
		ans = 0
		ok = True
		while val != 1:
			bl = True
			for i in ar:
				if val % i == 0:
					bl = False
					val //= i
					break
			ans += 1
			if bl == True:
				print(-1)
				ok = False
				break
		if ok:
			print(ans)


import sys
from collections import defaultdict, deque

def solve():
	(a, b) = [int(x) for x in input().split()]
	if a == b:
		print(0)
		return
	else:
		if a < b:
			(a, b) = (b, a)
		if a % b:
			print(-1)
			return
		else:
			x = a // b
			c = 0
			while x % 2 == 0:
				c += 1
				x //= 2
			if x != 1:
				print(-1)
			else:
				print(c // 3 + (c % 3 != 0))
t = 1
t = int(input())
for case in range(1, t + 1):
	ans = solve()


import math
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	c = 0
	f = 0
	if a == b:
		print(0)
		continue
	if a > b:
		(a, b) = (b, a)
	while a < b:
		if a << 3 <= b:
			a = a << 3
			c += 1
		elif a << 2 <= b:
			a = a << 2
			c += 1
		elif a << 1 <= b:
			a = a << 1
			c += 1
		else:
			break
	if a == b:
		print(c)
	else:
		print(-1)


def findCore(num):
	while num % 2 == 0:
		num //= 2
	return num

def conversion(smaller, larger):
	if findCore(smaller) != findCore(larger):
		return -1
	larger //= smaller
	moves = 0
	while larger >= 8:
		larger //= 8
		moves += 1
	if larger >= 2:
		moves += 1
	return moves
t = int(input())
while t:
	(a, b) = map(int, input().split(' '))
	if a > b:
		(a, b) = (b, a)
	print(conversion(a, b))
	t -= 1


t = int(input(''))
for i in range(t):
	(a, b) = map(int, input('').split(' '))
	tmp = True
	if a > b:
		if a % b != 0:
			tmp = False
	elif b % a != 0:
		tmp = False
	if tmp:
		op = 0
		tmp = True
		while a != b and tmp:
			if a < b:
				if a * 8 <= b:
					op += 1
					a *= 8
				elif a * 4 <= b:
					op += 1
					a *= 4
				elif a * 2 <= b:
					op += 1
					a *= 2
				else:
					tmp = False
			elif b * 8 <= a:
				op += 1
				b *= 8
			elif b * 4 <= a:
				op += 1
				b *= 4
			elif b * 2 <= a:
				op += 1
				b *= 2
			else:
				tmp = False
	if tmp:
		print(op)
	else:
		print(-1)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	ans = 0
	y = max(a, b)
	z = min(a, b)
	if y == z:
		ans = 0
	elif y % z != 0:
		ans = -1
	else:
		x = y // z
		while x > 1:
			if x % 8 == 0:
				ans += 1
				x = x // 8
			elif x % 4 == 0:
				ans += 1
				x = x // 4
			elif x % 2 == 0:
				ans += 1
				x = x // 2
			else:
				ans = -1
				break
	print(ans)


def count(a, b):
	ans = 0
	while a > b:
		if a % 2 == 0:
			a = a // 2
			ans += 1
		else:
			return -1
	if a == b:
		return ans
	return -1
import math
for _ in range(int(input())):
	(a, b) = list(map(int, input().split()))
	if a == b:
		print(0)
	elif a > b:
		if a % b == 0:
			ans = count(a, b)
			if ans == -1:
				print(ans)
			else:
				ans = math.ceil(ans / 3)
				print(ans)
		else:
			print(-1)
	elif b % a == 0:
		ans = count(b, a)
		if ans == -1:
			print(ans)
		else:
			ans = math.ceil(ans / 3)
			print(ans)
	else:
		print(-1)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	count1 = 0
	if b >= a and b % a == 0:
		r = b // a
	elif a > b and a % b == 0:
		r = a // b
	else:
		r = 0
		print('-1')
	if r != 0:
		while r % 8 == 0:
			r = r // 8
			count1 += 1
		while r % 4 == 0:
			r = r // 4
			count1 += 1
		while r % 2 == 0:
			r = r // 2
			count1 += 1
		if r == 1:
			print(count1)
		else:
			print('-1')


def number_of_operations(a, b):
	if a == b:
		return 0
	if a > b and a % b != 0 or (b > a and b % a != 0):
		return -1
	q = b // a if b > a else a // b
	shifts = 0
	while q // 8 > 0 and q % 8 == 0:
		shifts += 1
		q = q // 8
	while q // 4 > 0 and q % 4 == 0:
		shifts += 1
		q = q // 4
	while q // 2 > 0 and q % 2 == 0:
		shifts += 1
		q = q // 2
	if q != 1:
		return -1
	else:
		return shifts

def problem_a():
	t = int(input())
	for test_case in range(1, t + 1):
		(a, b) = map(int, input().split())
		print(number_of_operations(a, b))
problem_a()


from math import *
from collections import *
from operator import itemgetter
import bisect
from heapq import *
i = lambda : input()
ii = lambda : int(input())
iia = lambda : list(map(int, input().split()))
isa = lambda : list(input().split())
I = lambda : list(map(int, input().split()))
chrIdx = lambda x: ord(x) - 96
idxChr = lambda x: chr(96 + x)
t = ii()
for _ in range(t):
	(a, b) = iia()
	ans = 0
	if a == b:
		print(0)
	if a > b:
		if a % b == 0 and bin(a // b)[2:].count('1') == 1:
			m = log(a // b, 2)
			ans += m // 3
			ans += m % 3 // 2
			ans += m % 3 % 2
			print(int(ans))
		else:
			print(-1)
	if a < b:
		if b % a == 0 and bin(b // a)[2:].count('1') == 1:
			m = log(b // a, 2)
			ans += m // 3
			ans += m % 3 // 2
			ans += m % 3 % 2
			print(int(ans))
		else:
			print(-1)


from math import *
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	ans = -1
	if a == b:
		ans = 0
	else:
		if b > a:
			(a, b) = (b, a)
		k = a % b
		if k != 0:
			pass
		else:
			c = a // b
			while c > 1:
				if c % 8 == 0:
					if ans == -1:
						ans = 0
					ans = ans + 1
					c = c // 8
				elif c % 4 == 0:
					if ans == -1:
						ans = 0
					ans = ans + 1
					c = c // 4
				elif c % 2 == 0:
					if ans == -1:
						ans = 0
					ans = ans + 1
					c = c // 2
				else:
					ans = -1
					break
	print(ans)


from sys import stdin
t = int(stdin.readline())
for _ in range(t):
	(a, b) = list(map(int, stdin.readline().rstrip().split(' ')))
	aCounts = 0
	bCounts = 0
	if a == b:
		print(0)
		continue
	while a % 2 == 0:
		aCounts += 1
		a = a // 2
	while b % 2 == 0:
		bCounts += 1
		b = b // 2
	if a != b:
		print(-1)
	else:
		diff = abs(aCounts - bCounts)
		answer = 0
		answer += diff // 3
		diff = diff % 3
		answer += diff // 2
		diff = diff % 2
		answer += diff // 1
		print(answer)


n = int(input())

def cal(d):
	r = 0
	while d % 8 == 0:
		r += 1
		d = d // 8
	while d % 4 == 0:
		r += 1
		d = d // 4
	while d % 2 == 0:
		r += 1
		d = d // 2
	return r
for _ in range(n):
	(a, b) = map(int, input().split())
	x = max(a, b)
	y = a + b - x
	if x % y == 0:
		d = x // y
		s = bin(d)
		if s.count('1') == 1:
			print(cal(d))
		else:
			print(-1)
	else:
		print(-1)


from collections import Counter
from collections import defaultdict
from collections import deque
import math
import heapq
import sys
input = sys.stdin.readline
from bisect import *
rs = lambda : input().strip()
ri = lambda : int(input())
rl = lambda : list(map(int, input().split()))
rls = lambda : list(map(str, input().split()))
t = int(input())
for _ in range(0, t):
	(a, b) = rl()
	if b > a:
		(a, b) = (b, a)
	if a % b != 0:
		print(-1)
		continue
	else:
		x = a // b
		ans = 0
		while x != 1:
			if x % 8 == 0:
				x = x // 8
			elif x % 4 == 0:
				x = x // 4
			elif x % 2 == 0:
				x = x // 2
			else:
				ans = -1
				break
			ans = ans + 1
	print(ans)


def equate(a, b, cnt):
	if a == b:
		return cnt
	else:
		if a < b:
			(a, b) = (b, a)
		if a > b:
			if a % 8 == 0 and a >> 3 >= b:
				a = a >> 3
			elif a % 4 == 0 and a >> 2 >= b:
				a = a >> 2
			elif a % 2 == 0 and a >> 1 >= b:
				a = a >> 1
			else:
				return -1
			return equate(a, b, cnt + 1)
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	res = equate(a, b, 0)
	print(res)


from sys import stdin
from sys import stdout
from math import *
sprint = stdout.write
sinput = stdin.readline

def func():
	(a, b) = [int(x) for x in sinput().split()]
	(a, b) = sorted([a, b])
	if b % a == 0 and log(b // a) / log(2) - int(log(b // a) / log(2)) < 0.0001 and (2 ** int(log(b // a) / log(2)) == b // a):
		a = log(b // a) / log(2)
		b = a // 3
		a = a - a // 3 * 3
		b += a // 2
		a = a - a // 2 * 2
		b += a
		print(int(b))
	else:
		print(-1)
		return
t = int(sinput())
while t != 0:
	if t == 1000 - 84 + 1 + t:
		(a, b) = [int(x) for x in sinput().split()]
		print(b, end=' ')
		print(b)
		t -= 1
	else:
		t -= 1
		func()


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	cn = 0
	if a < b:
		i = 8
		while i >= 2:
			if a * i == b:
				a = a * i
				cn += 1
				break
			elif a * i > b:
				i = i // 2
			else:
				a = a * i
				cn += 1
		else:
			cn = -1
		print(cn)
	elif a > b:
		i = 8
		while i >= 2:
			if a % i != 0:
				i = i // 2
				continue
			if a // i == b:
				a = a // i
				cn += 1
				break
			elif a // i < b:
				i = i // 2
			else:
				a = a // i
				cn += 1
		else:
			cn = -1
		print(cn)
	else:
		print(cn)


from collections import deque
from collections import OrderedDict
import math
import sys
import os
from io import BytesIO
import threading
import bisect
import heapq
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
input = lambda : sys.stdin.readline().rstrip('\r\n')
ara = [0] * 100005
listOdd = list()

def aratosfen():
	global ara
	for i in range(2, int(math.sqrt(len(ara)))):
		if ara[i] == 0:
			for j in range(i * 2, len(ara), i):
				ara[j] = 1
	global listOdd
	for i in range(2, len(ara)):
		if ara[i] == 0:
			listOdd.append(i)

def run(str1, met, omet, f, l, s):
	fl = False
	cOp = 0
	for i in range(f, l, s):
		if str1[i] == met:
			fl = True
		elif fl == True and str1[i] == omet:
			cOp += 1
	return cOp
for t in range(int(input())):
	(a, b) = map(int, input().split())
	answer = 0
	if a == b:
		print(answer)
		continue
	elif a > b:
		while a != b:
			if a % 2 != 0:
				answer = -1
				break
			else:
				a = a // 2
				answer += 1
	else:
		while a != b:
			if a > b:
				answer = -1
				break
			else:
				a *= 2
				answer += 1
	if answer == -1:
		print(-1)
		continue
	answer = answer // 3 + (1 if answer % 3 != 0 else 0)
	print(answer)


def solve():
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	else:
		if a > b:
			(a, b) = (b, a)
		if b % a != 0:
			print(-1)
		else:
			d = b // a
			d2 = d
			while d2 % 2 == 0:
				d2 //= 2
			if d2 > 1:
				print(-1)
			else:
				ans = 0
				while d > 1:
					d //= 8
					ans += 1
				print(ans)
t = int(input())
for _ in range(t):
	solve()


def main():
	from sys import stdin
	from sys import stdout
	input = stdin.readline
	print = stdout.write
	t = int(input())
	for _ in range(t):
		(a, b) = list(map(int, input().split()))
		(a, b) = (min(a, b), max(a, b))
		(a, b) = (str(bin(a))[2:], str(bin(b))[2:])
		if a == b[:len(a)] and b[len(a):] == '0' * (len(b) - len(a)):
			(answer, counter) = (0, len(b) - len(a))
			answer += counter // 3
			counter %= 3
			answer += counter // 2
			counter %= 2
			answer += counter
			print('{0}\n'.format(answer))
		else:
			print('-1\n')
main()


import math

def main():
	(a, b) = map(int, input().split())
	temp = min(a, b)
	temp2 = max(a, b)
	ans = 0
	cnt = 0
	while temp < temp2:
		temp = temp * 2
		cnt += 1
	ans = cnt // 3
	if cnt % 3 != 0:
		ans += 1
	if temp == temp2:
		print(ans)
	else:
		print(-1)

def test():
	t = int(input())
	while t:
		main()
		t -= 1
test()


import sys

def op(a, b):
	if a == b:
		return 0
	if a > b:
		tmp = a
		a = b
		b = tmp
	while a & 1 == 0 and b & 1 == 0:
		a = a >> 1
		b = b >> 1
	count_b = 0
	while b & 1 == 0:
		count_b += 1
		b = b >> 1
	if a != b:
		return -1
	if count_b > 0 and count_b <= 3:
		return 1
	n_steps = count_b // 3
	rem = count_b % 3
	n_twos = rem // 2
	n_ones = rem % 2
	return n_steps + n_twos + n_ones
N = int(sys.stdin.readline().rstrip())
for _ in range(N):
	line = sys.stdin.readline().rstrip().split(' ')
	(a, b) = list(map(int, line))
	print(op(a, b))


def main():
	n = int(input())
	for j in range(n):
		(a, b) = map(int, input().split())
		if a == b:
			print(0)
		else:
			if a > b and a % b == 0:
				tmp = a // b
			elif b > a and b % a == 0:
				tmp = b // a
			else:
				tmp = 0
			counter = 0
			while tmp > 1 and tmp % 8 == 0:
				tmp //= 8
				counter += 1
			while tmp > 1 and tmp % 4 == 0:
				tmp //= 4
				counter += 1
			while tmp > 1 and tmp % 2 == 0:
				tmp //= 2
				counter += 1
			if tmp == 1:
				print(counter)
			elif tmp > 1 or tmp == 0:
				print(-1)
main()


from __future__ import division, print_function
import sys
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
if os.path.exists('out.txt'):
	sys.stdout = open('out.txt', 'w')

def input():
	return sys.stdin.readline()

def mapi(arg=0):
	return map(int if arg == 0 else str, input().split())
from math import *
for _ in range(int(input())):
	(a, b) = mapi()
	(b, a) = (max(a, b), min(a, b))
	if a == b:
		print(0)
	elif b % a != 0:
		print(-1)
	elif b // a % 2:
		print(-1)
	else:
		val = b // a
		tmp = int(log2(val))
		if 2 ** tmp != val:
			print(-1)
			continue
		print(tmp // 3 + tmp % 3 // 2 + tmp % 3 % 2)


def f(a):
	count = 0
	while a & 1 == 0:
		a >>= 1
		count += 1
	return (count, a)
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	(t1, t2) = (f(a), f(b))
	if t1[1] != t2[1]:
		print(-1)
		continue
	temp = abs(t1[0] - t2[0])
	if temp % 3:
		print(1 + temp // 3)
	else:
		print(temp // 3)


from math import *
for u in range(int(input())):
	(x, y) = map(int, input().split())
	if x == y:
		print(0)
	else:
		if x > y:
			(x, y) = (y, x)
		s = y // x
		if y % x == 0:
			if s & s - 1 == 0:
				b = len(bin(s)) - 3
				c = b // 3
				if b % 3 == 0:
					print(c)
				else:
					print(c + 1)
			else:
				print(-1)
		else:
			print(-1)


def minops(a, b):
	ops = 0
	while a < b:
		if a * 8 <= b:
			a *= 8
		elif a * 4 <= b:
			a *= 4
		elif a * 2 <= b:
			a *= 2
		else:
			break
		ops += 1
	return ops if a == b else -1
T = int(input())
for _ in range(T):
	(curr, goal) = map(int, input().strip().split())
	(a, b) = (min(curr, goal), max(curr, goal))
	print(minops(a, b))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = max(n, m)
	b = min(n, m)
	if a == b:
		print(0)
		continue
	c = 0
	f = 0
	while True:
		t = b * 8
		if t == a:
			c += 1
			f = 1
			break
		if t > a:
			t = b * 4
			if t == a:
				c += 1
				f = 1
				break
			if t > a:
				t = b * 2
				if t == a:
					c += 1
					f = 1
					break
				if t > a:
					break
		c += 1
		b = t
	if f == 1:
		print(c)
	else:
		print(-1)


from math import ceil as c

def h2(n1, n2):
	k = 0
	while n1 % 2 == 0:
		n1 //= 2
		k += 1
	f1 = n1
	x = k
	k = 0
	while n2 % 2 == 0:
		n2 //= 2
		k += 1
	f2 = n2
	y = k
	if f1 == f2:
		e = abs(x - y)
		r = c(e / 3)
		print(r)
	else:
		print(-1)
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	h2(a, b)


from sys import stdin, stdout
import heapq as hq
from collections import defaultdict
from math import ceil
t = int(input())
for tc in range(t):
	(a, b) = list(map(int, stdin.readline().split()))
	res = 0
	ma = 0
	mb = 0
	while a != b:
		if a > b:
			if a % 2 == 1:
				break
			a //= 2
			ma += 1
		else:
			if b % 2 == 1:
				break
			b //= 2
			mb += 1
	if a == b:
		res = ceil(ma / 3) + ceil(mb / 3)
	else:
		res = -1
	stdout.write(str(res) + '\n')


import math as mt
import sys, string
input = sys.stdin.readline
from collections import defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
t = I()
l = [-3, -2, -1, 0, 1, 2, 3]
for i in range(t):
	(a, b) = M()
	x = bin(a)[2:]
	y = bin(b)[2:]
	if x < y:
		flag = 0
		for j in range(len(x)):
			if x[j] != y[j]:
				flag = 1
				break
		if flag == 1:
			print(-1)
		else:
			for j in range(len(x), len(y)):
				if y[j] == '1':
					flag = 1
					break
			if flag:
				print(-1)
			else:
				print(mt.ceil((len(y) - len(x)) / 3))
	else:
		g = x[:]
		x = y[:]
		y = g[:]
		flag = 0
		for j in range(len(x)):
			if x[j] != y[j]:
				flag = 1
				break
		if flag == 1:
			print(-1)
		else:
			for j in range(len(x), len(y)):
				if y[j] == '1':
					flag = 1
					break
			if flag:
				print(-1)
			else:
				print(mt.ceil((len(y) - len(x)) / 3))


def check(x):
	global q
	if x == 2 or x == 4 or x == 8:
		q += 1
		print(q)
		return q
	elif x % 8 == 0:
		q += 1
		check(x // 8)
	elif x % 4 == 0:
		q += 1
		check(x // 4)
	elif x % 2 == 0:
		q += 1
		check(x // 2)
	else:
		print(-1)
for i in range(int(input())):
	q = 0
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	elif b % a == 0:
		x = b // a
		check(x)
	elif a % b == 0:
		x = a // b
		check(x)
	else:
		print(-1)


import math

def solve():
	(a, b) = map(int, input().split())
	if max(a, b) % min(a, b) == 0:
		x = max(a, b) // min(a, b)
		n = math.log2(x)
		if int(n) == n:
			eight = n // 3
			n = n - n // 3 * 3
			four = n // 2
			n = n - n // 2 * 2
			two = n // 1
			count = int(eight + four + two)
			check = eight * 3 + four * 2 + two
			if min(a, b) * int(2 ** check) == max(a, b):
				print(count)
			else:
				print(-1)
		else:
			print(-1)
	else:
		print(-1)
t = int(input())
for i in range(t):
	solve()


t = int(input())
res = []
for i in range(t):
	(a, b) = map(int, input().split())
	count = 0
	mcount = 0
	f = 0
	if a >= b:
		while a >= b:
			if a == b:
				f = 1
				break
			if a % 2 == 0:
				a = a >> 1
			else:
				break
			count += 1
	else:
		while b > a:
			if b % 2 == 0:
				b = b >> 1
			else:
				break
			count += 1
			if a == b:
				f = 1
				break
	if f == 1:
		if count >= 3:
			mcount = count // 3
			count %= 3
		if count >= 2:
			mcount += count // 2
			count %= 2
		if count >= 1:
			mcount += count // 1
		res.append(mcount)
	else:
		res.append(-1)
for i in res:
	print(i)


import math
n = int(input())
for _ in range(n):
	(x, y) = map(int, input().split())
	if x > y:
		(x, y) = (y, x)
	if x == y:
		print('0')
	elif y % x != 0:
		print('-1')
	else:
		m = y / x
		l = 0
		while x < y:
			x *= 2
			l += 1
		if x == y:
			o = l // 3
			l = l - o * 3
			p = l // 2
			l = l - p * 2
			print(o + p + l)
		else:
			print('-1')


for t in range(int(input())):
	(a, b) = map(int, input().split())
	a1 = 0
	b1 = 0
	while a % 2 == 0:
		a //= 2
		a1 += 1
	while b % 2 == 0:
		b //= 2
		b1 += 1
	if a != b:
		print(-1)
	else:
		print((abs(a1 - b1) + 2) // 3)


import math
for t in range(int(input())):
	(a, b) = map(int, input().split())
	g = max(a, b)
	h = min(a, b)
	if g % h != 0:
		print(-1)
	else:
		c = 0
		n = g // h
		if n & n - 1 != 0:
			print(-1)
		elif n == 2 or n == 4 or n == 8:
			print(1)
		else:
			while n >= 8:
				n = n // 8
				c = c + 1
			while n >= 4:
				n = n // 4
				c = c + 1
			while n >= 2:
				n = n // 2
				c = c + 1
			print(c)


import math
n = int(input())
for i in range(n):
	line = input().split(' ')
	a = int(line[0])
	b = int(line[1])
	if b > a:
		tmp = a
		a = b
		b = tmp
	cent = True
	x = a / b
	if x != math.ceil(x):
		print(-1)
		cent = False
	cont = 0
	while cent:
		if b == a:
			print(cont)
			cent = False
		elif a >= b * 8:
			b = b * 8
			cont += 1
		elif a >= b * 4:
			b = b * 4
			cont += 1
		elif a >= b * 2:
			b = b * 2
			cont += 1
		else:
			print(-1)
			cent = False


from functools import reduce
read = input
mi = lambda dt: map(dt, read().split())
cin = lambda : int(read())
for _ in range(cin()):
	(a, b) = mi(int)
	(mx, mn) = (max(a, b), min(a, b))
	if mx % mn != 0:
		print(-1)
	else:
		ct = 0
		d = mx // mn
		flag = True
		while d != 1:
			if d % 2 == 0:
				ct += 1
				d //= 2
			else:
				flag = False
				break
		if flag:
			ans = ct // 3
			ct = ct % 3
			ans += ct // 2
			ct = ct % 2
			ans += ct
			print(ans)
		else:
			print(-1)


import os
import random
import sys
from io import BytesIO, IOBase
import math

def inputIntArray():
	return list(map(int, input().rstrip().split()))

def inputArray():
	return input().rstrip().split()

def inputVars():
	return map(int, input().rstrip().split())

def inputNum():
	return int(input())

def main():
	for _ in range(inputNum()):
		(a, b) = inputVars()
		(a, b) = (min(a, b), max(a, b))
		if a == b:
			print(0)
			continue
		if b % a != 0:
			print(-1)
			continue
		rest = b // a
		cnt = 0
		while rest % 8 == 0:
			rest //= 8
			cnt += 1
		while rest % 4 == 0:
			rest //= 4
			cnt += 1
		while rest % 2 == 0:
			rest //= 2
			cnt += 1
		if cnt == 0 or rest != 1:
			print(-1)
		else:
			print(cnt)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import bisect
import decimal
from decimal import Decimal
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
decimal.getcontext().prec = 46

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

def lcm(a, b):
	return a * b // math.gcd(a, b)

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

def list_input():
	return list(map(int, input().split()))

def num_input():
	return map(int, input().split())

def string_list():
	return list(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	return int(n, 2)

def DFS(n, s, adj):
	visited = [False for i in range(n)]
	stack = []
	stack.append(s)
	while len(stack):
		s = stack[-1]
		stack.pop()
		if not visited[s]:
			visited[s] = True
		for node in adj[s]:
			if not visited[node]:
				stack.append(node)

def solve():
	(a, b) = sorted(num_input())
	count = temp = 0
	while a != b and temp == 0:
		if a * 8 <= b:
			a = a * 8
			count += 1
		elif a * 4 <= b:
			a = a * 4
			count += 1
		elif a * 2 <= b:
			a = a * 2
			count += 1
		else:
			temp = 1
	if temp == 1:
		print(-1)
		return
	print(count)
t = int(input())
for _ in range(t):
	solve()


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	big = max(a, b)
	small = min(a, b)
	if big % small != 0:
		print(-1)
		continue
	mult = big // small
	count = 0
	while True:
		if mult % 8 == 0:
			mult = mult // 8
			count += 1
		elif mult % 4 == 0:
			mult = mult // 4
			count += 1
		elif mult % 2 == 0:
			mult = mult // 2
			count += 1
		elif mult == 1:
			print(count)
			break
		else:
			print(-1)
			break


def cnt(x):
	if x == 1:
		return 0
	if x % 2:
		return -1
	if x >= 8 and x % 8 == 0:
		r = cnt(x // 8)
		if r == -1:
			return -1
		return r + 1
	if x == 4:
		return 1
	if x == 2:
		return 1
	return -1
T = int(input())
for _ in range(T):
	n = [int(__) for __ in input().split()]
	a = min(n)
	b = max(n)
	if b % a == 0:
		print(cnt(b // a))
	else:
		print(-1)


t = int(input())

def cnt(n):
	ans = 0
	while n != 1:
		if n % 8 == 0:
			ans += 1
			n //= 8
		elif n % 4 == 0:
			ans += 1
			n //= 4
		elif n % 2 == 0:
			ans += 1
			n //= 2
		else:
			break
	if n != 1:
		return -1
	return ans
for _ in range(t):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(cnt(a // b))
	elif b % a == 0:
		print(cnt(b // a))
	else:
		print(-1)


def dp(m, s, pre):
	if m == s:
		return 0
	m = bin(m)[2:]
	s = bin(s)[2:]
	if m.find(s) == -1 or '1' in m[len(s):] or m.find(s) != 0:
		return -1
	num = len(m) - len(s)
	return pre[num]
ans = []
pre = [0] * 100
pre[1] = 1
pre[2] = 1
pre[3] = 1
for i in range(4, 100):
	pre[i] = min(min(pre[i - 3] + 1, pre[i - 2] + 1), pre[i - 1] + 1)
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	ans.append(dp(max(n, m), min(m, n), pre))
for i in ans:
	print(i)


def solve():
	(a, b) = [int(x) for x in input().split()]
	mi = min(a, b)
	ma = max(a, b)
	a = mi
	b = ma
	count = 0
	if a == b:
		return 0
	if b % a != 0:
		return -1
	else:
		q = b // a
		temp = q
		while temp % 8 == 0:
			temp //= 8
			count += 1
			if temp == 1:
				return count
		while temp % 4 == 0:
			temp //= 4
			count += 1
			if temp == 1:
				return count
		while temp % 2 == 0:
			temp //= 2
			count += 1
			if temp == 1:
				return count
	return -1
t = int(input())
while t:
	print(solve())
	t -= 1


import math
test = int(input())
for tes in range(test):
	(a, b) = list(map(int, input().split()))
	x = min(a, b)
	y = max(a, b)
	if y % x != 0:
		print(-1)
		continue
	val = y // x
	done = False
	ans = 0
	while True:
		if val == 1:
			done = True
			break
		if val % 2 != 0:
			break
		if val % 8 == 0:
			val = val // 8
		elif val % 4 == 0:
			val = val // 4
		elif val % 2 == 0:
			val = val // 2
		ans += 1
	if done:
		print(ans)
	else:
		print(-1)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	larger = max(a, b)
	smaller = min(a, b)
	i = 0
	while True:
		if smaller == larger:
			if i % 3 == 0:
				print(i // 3)
			else:
				print(i // 3 + 1)
			break
		if smaller > larger:
			print(-1)
			break
		i += 1
		smaller *= 2


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	t = 0
	p = 0
	r = 0
	x = 0
	y = 0
	if a < b:
		(a, b) = (b, a)
	while a > b:
		if a % 2 == 0:
			a = a // 2
			t += 1
		else:
			r += 1
			break
	if r > 0:
		print(-1)
	elif a == b:
		x = t // 3
		t = t - x * 3
		y = t // 2
		t = t - y * 2
		print(x + y + t)
	else:
		print(-1)


import sys
input = lambda : sys.stdin.readline().rstrip()
mod = 10 ** 9 + 7
t = int(input())
ans = []
for _ in range(t):
	(a, b) = map(int, input().split())
	a_ = 0
	b_ = 0
	while a % 2 == 0:
		a //= 2
		a_ += 1
	while b % 2 == 0:
		b //= 2
		b_ += 1
	if a != b:
		print(-1)
		continue
	ans = (max(a_, b_) - min(a_, b_)) // 3
	ans += int((max(a_, b_) - min(a_, b_)) % 3 != 0)
	print(ans)


from sys import stdin
from math import log
input = stdin.readline

def list_input():
	return list(map(int, input().split()))

def sep_input():
	return map(int, input().split())
l = set()
for i in range(200):
	l.add(2 ** i)
for _ in range(int(input())):
	(a, b) = sep_input()
	if a >= b and a % b == 0:
		c = a // b
		if c in l:
			need = int(log(c, 2))
			ans1 = need // 3
			ans2 = (need - 3 * ans1) // 2
			ans3 = need - 3 * ans1 - 2 * ans2
			print(ans1 + ans2 + ans3)
		else:
			print(-1)
	elif b >= a and b % a == 0:
		c = b // a
		if c in l:
			need = int(log(c, 2))
			ans1 = need // 3
			ans2 = (need - 3 * ans1) // 2
			ans3 = need - 3 * ans1 - 2 * ans2
			print(ans1 + ans2 + ans3)
		else:
			print(-1)
	else:
		print(-1)


import sys
input = sys.stdin.readline
from math import ceil, floor, factorial

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
for _ in range(int(input())):
	(a, b) = sorted(int_array())
	if a == b:
		print(0)
		continue
	count = 0
	while b > a and b % 2 == 0:
		count += 1
		b = b // 2
	if a == b:
		ets = count // 3
		count = count % 3
		tws = count // 2
		count = count % 2
		ons = count // 1
		ans = ets + tws + ons
		print(ans)
	else:
		print(-1)


import sys
import random
strInp = lambda : input().strip().split()
intInp = lambda : list(map(int, strInp()))
for t in range(int(input())):
	(a, b) = intInp()
	if a > b:
		c = b
		d = a
	else:
		c = a
		d = b
	if a == b:
		print(0)
	else:
		ans = 0
		for i in range(1005):
			if c * 8 <= d:
				c = c * 8
				ans += 1
			elif c * 4 <= d:
				c = c * 4
				ans += 1
			else:
				c = c * 2
				ans += 1
			if c == d:
				break
			if c > d:
				ans = -1
				break
		print(ans)


def final_fun(a, b):
	if a == b:
		return 0
	m = max(a, b)
	n = min(a, b)
	if n < m:
		x = n
		count = 1
		var = 0
		while True:
			l = [2 * x, 4 * x, 8 * x]
			if m in l:
				break
			elif m > l[2]:
				x = l[2]
				count = count + 1
			else:
				var = 1
				break
		if var == 1:
			return -1
		else:
			return count
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	print(final_fun(a, b))


import sys
import math
input = lambda : sys.stdin.readline().strip()
t = int(input())
while t:
	t -= 1
	(a, b) = map(int, input().split())
	if b == a:
		print(0)
		continue
	if b > a:
		if b % a == 0:
			x = b // a
			if x and (not x & x - 1):
				x = math.floor(math.log2(x))
				ans = 0
				while x >= 3:
					x -= 3
					ans += 1
				while x >= 2:
					x -= 2
					ans += 1
				ans += x
				print(ans)
			else:
				print(-1)
		else:
			print(-1)
	elif a % b == 0:
		x = a // b
		if x and (not x & x - 1):
			x = math.floor(math.log2(x))
			ans = 0
			while x >= 3:
				x -= 3
				ans += 1
			while x >= 2:
				x -= 2
				ans += 1
			ans += x
			print(ans)
		else:
			print(-1)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	ca = 0
	while a % 2 == 0:
		a //= 2
		ca += 1
	cb = 0
	while b % 2 == 0:
		b //= 2
		cb += 1
	if a != b:
		print(-1)
	else:
		print((abs(cb - ca) + 2) // 3)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	a1 = max(a, b)
	b1 = min(a, b)
	if a1 % b1 == 0:
		x = a1 // b1
		s = 0
		if x == 1:
			print(0)
			continue
		if x & x - 1 == 0:
			while x:
				if x > 8:
					x = x / 8
					s += 1
				else:
					break
			print(s + 1)
		else:
			print(-1)
	else:
		print(-1)


t = int(input())
for i in range(t):
	(a, b) = [int(i) for i in input().split()]
	(a, b) = (max(a, b), min(a, b))
	if a % b != 0:
		print(-1)
	else:
		f = True
		i = 0
		c = a // b
		while c > 1:
			if c % 2 == 0:
				c //= 2
				i += 1
			else:
				f = False
				break
		if not f:
			print(-1)
		else:
			print(i // 3 + (i % 3 != 0))


for _ in range(int(input())):
	(x, y) = list(map(int, input().split()))
	if x == y:
		print(0)
	elif x % y and y % x:
		print(-1)
	elif x % y == 0:
		cou = 0
		k = 0
		while x != y:
			if x % 8 == 0 and x // 8 >= y:
				cou += 1
				x //= 8
			elif x % 4 == 0 and x // 4 >= y:
				cou += 1
				x //= 4
			elif x % 2 == 0 and x // 2 >= y:
				cou += 1
				x //= 2
			else:
				print(-1)
				k = 1
				break
		if k == 0:
			print(cou)
	elif y % x == 0:
		cou = 0
		k = 0
		while x != y:
			if x * 8 <= y:
				x *= 8
				cou += 1
			elif x * 4 <= y:
				x *= 4
				cou += 1
			elif x * 2 <= y:
				cou += 1
				x *= 2
			else:
				print(-1)
				k = 1
				break
		if k == 0:
			print(cou)


def gcd(a, b):
	return a if b == 0 else gcd(b, a % b)

def getDivideOperations(a, b):
	c = 0
	while a > b:
		if a % 8 == 0 and a >> 3 >= b:
			a >>= 3
		elif a % 4 == 0 and a >> 2 >= b:
			a >>= 2
		elif a % 2 == 0 and a >> 1 >= b:
			a >>= 1
		else:
			return -1
		c += 1
	return c

def getMultiplyOperations(a, b):
	c = 0
	while a < b:
		if a << 3 <= b:
			a <<= 3
		elif a << 2 <= b:
			a <<= 2
		elif a << 1 <= b:
			a <<= 1
		else:
			return -1
		c += 1
	return c
t = int(input())
while t != 0:
	(a, b) = map(int, input().split())
	if a != b:
		print(getDivideOperations(a, b) if a > b else getMultiplyOperations(a, b))
	else:
		print(0)
	t -= 1


import sys

def arr():
	return list(map(int, input().split()))
input = sys.stdin.readline
from collections import defaultdict
import math
for _ in range(int(input())):
	(A, B) = map(int, input().split())
	if A == B:
		print(0)
		continue
	if A > B:
		(A, B) = (B, A)
	count = 0
	if B % A != 0:
		print(-1)
	else:
		x = B // A
		t = 0
		for i in range(1, 64):
			if pow(2, i) == x:
				t = i
				break
		if t == 0:
			print(-1)
			continue
		count += t // 3
		t = t % 3
		count += t // 2
		t = t % 2
		count += t
		print(count)


from sys import stdin as cin
lmap = lambda f, v: list(map(f, v))
OPC = {2 ** i: (i - 1) // 3 + 1 for i in range(60)}

def count_ops(a, b):
	if a <= b and b % a == 0:
		return OPC.get(b // a, -1)
	if a % b == 0:
		return OPC.get(a // b, -1)
	return -1

def main():
	t = int(next(cin).strip())
	for i in range(t):
		(a, b) = lmap(int, next(cin).strip().split())
		print(count_ops(a, b))
main()


def get_ops(a, b):
	ops = 0
	if a == b:
		return 0
	counter = 3
	while counter:
		if a << counter <= b:
			a = a << counter
			ops += 1
			continue
		counter -= 1
	if a == b:
		return ops
	return -1
for i in range(int(input())):
	(a, b) = tuple([int(i) for i in input().split(' ')])
	if a < b:
		print(get_ops(a, b))
	else:
		print(get_ops(b, a))


T = int(input())

def solve():
	[A, B] = list(map(int, input().split()))

	def helper(A, B):
		count = 0
		while A != B:
			if A > B:
				return False
			if 8 * A <= B:
				A *= 8
				count += 1
			elif 4 * A <= B:
				A *= 4
				count += 1
			elif 2 * A <= B:
				A *= 2
				count += 1
			else:
				return -1
		return count
	return helper(min(A, B), max(A, B))
for _ in range(T):
	print(solve())


def read_int():
	n = int(input())
	return n

def read_ints():
	ints = [int(x) for x in input().split(' ')]
	return ints

def solve(a, b):
	if a == b:
		return 0
	(a, b) = (min(a, b), max(a, b))
	ba = bin(a)
	bb = bin(b)
	if bb.find(ba) != 0:
		return -1
	l = len(ba)
	shift = bb[l:]
	if shift.count('1') != 0:
		return -1
	cntr = len(shift)
	res = 0
	res += cntr // 3
	cntr = cntr % 3
	res += cntr // 2
	cntr = cntr % 2
	res += cntr
	return res
t = read_int()
for case in range(t):
	(a, b) = read_ints()
	sol = solve(a, b)
	print(sol)


for _ in range(int(input())):
	a = list(map(int, input().split()))
	(m, s, c) = (max(a), min(a), 0)
	while s < m:
		s = s * 8
		c += 1
	if s == m or m == s // 4 or m == s // 2:
		print(c)
	else:
		print(-1)


def len_bi(x):
	count = 0
	while x > 0:
		count += 1
		x //= 2
	return count

def fix(a, b):
	n = len_bi(a)
	m = len_bi(b)
	k = n - m
	sum = 0
	if a == b * 2 ** k:
		sum += k // 3
		k = k % 3
		sum += k // 2
		k = k % 2
		sum += k
		return sum
	else:
		return -1
t = int(input())
for i in range(t):
	(x, y) = map(int, input().split())
	if x >= y:
		print(fix(x, y))
	else:
		print(fix(y, x))


def solve():
	arr = list(map(int, input().split()))
	arr.sort()
	if arr[0] == arr[1]:
		print(0)
	elif arr[1] % arr[0] != 0:
		print(-1)
	else:
		ans = arr[1] // arr[0]
		count = 0
		while ans > 1:
			if ans != 1 and ans % 2 != 0:
				print(-1)
				return
			ans = ans // 2
			count += 1
		ans = count // 3
		if count % 3 == 2:
			print(ans + 1)
		else:
			print(ans + count % 3)
t = int(input())
for i in range(0, t):
	solve()


import sys
input = sys.stdin.readline
import math

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input().strip()
	return list(s[:len(s)])

def invr():
	return map(int, input().strip().split())

def from_file(f):
	return f.readline

def solution(a, b):
	if b > a:
		(a, b) = (b, a)
	if a % b != 0:
		return -1
	mul = a // b
	bitpos = 0
	for bitpos in range(80):
		if mul == 1 << bitpos:
			break
	else:
		return -1
	res = 0
	res += bitpos // 3
	bitpos %= 3
	res += bitpos // 2
	bitpos %= 2
	res += bitpos
	return res
t = inp()
for _ in range(t):
	(a, b) = invr()
	print(solution(a, b))


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	m = max(x, y)
	n = min(x, y)
	if x == y:
		print(0)
	elif m / n == m // n:
		count = 0
		while n < m:
			count += 1
			if m // n >= 8:
				n = n * 8
			elif m // n >= 4:
				n = n * 4
			else:
				n = n * 2
		if m == n:
			print(count)
		else:
			print(-1)
	else:
		print(-1)


from sys import stdin
input = stdin.buffer.readline
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if b > a and b % a == 0:
		b //= a
		k = 0
		while 1 << k < b:
			k += 1
		if 1 << k == b:
			print((k + 2) // 3)
		else:
			print(-1)
	elif a >= b and a % b == 0:
		a //= b
		k = 0
		while 1 << k < a:
			k += 1
		if 1 << k == a:
			print((k + 2) // 3)
		else:
			print(-1)
	else:
		print(-1)


import math
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	l = max(a, b)
	m = min(a, b)
	if l == m:
		print(0)
	elif l % m != 0:
		print(-1)
	else:
		k = l // m
		c = 0
		while k % 8 == 0:
			k //= 8
			c += 1
		while k % 4 == 0:
			k //= 4
			c += 1
		while k % 2 == 0:
			k //= 2
			c += 1
		if k == 1:
			print(c)
		else:
			print(-1)


import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	(n, m) = map(int, input().split())
	if n > m:
		(n, m) = (m, n)
	c = 0
	while n < m:
		n = n << 1
		c = c + 1
	if n != m:
		print(-1)
	else:
		(sv, rv) = (c // 3, c % 3)
		(sv, rv) = (sv + rv // 2, rv % 2)
		sv = sv + rv
		print(sv)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	op = 0
	if a > b:
		while a > b and a & 1 == 0:
			a >>= 1
			op += 1
	else:
		while a < b:
			a <<= 1
			op += 1
	if a != b:
		print(-1)
	else:
		r = op % 3
		op //= 3
		print(op + r // 2 + r % 2)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	(ra, rb) = (n, m)
	(x, y) = (0, 0)
	while ra % 2 == 0:
		x += 1
		ra = ra // 2
	while rb % 2 == 0:
		y += 1
		rb = rb // 2
	if ra != rb:
		print('-1')
	elif n == m:
		print('0')
	elif abs(x - y) % 3 == 0:
		print(abs(x - y) // 3)
	else:
		print(abs(x - y) // 3 + 1)


def is2pow(n):
	i = 0
	while True:
		if 2 ** i == n:
			return True
		elif 2 ** i > n:
			return False
		i += 1

def compute(f, s):
	if f == s:
		return 0
	if f > s:
		temp = s
		s = f
		f = temp
	if not s % f == 0:
		return -1
	move = 0
	while True:
		if s / f >= 8:
			f *= 8
		elif s / f >= 4:
			f *= 4
		elif s / f >= 2:
			f *= 2
		else:
			return -1
		move += 1
		if s == f:
			return move
N = int(input())
for i in range(N):
	line = input().split()
	print(compute(int(line[0]), int(line[1])))


T = int(input())
for _ in range(T):
	(a, b) = list(map(int, input().split()))
	big = max(bin(a)[2:], bin(b)[2:])
	small = min(bin(a)[2:], bin(b)[2:])
	window = len(small)
	idx = big.find(small)
	if idx != 0:
		print(-1)
	else:
		bits = len(big) - (idx + window)
		if big[idx + window:].find('1') != -1:
			print(-1)
		else:
			a = bits // 3 + bits % 3 // 2 + bits % 3 % 2
			print(a)


t = int(input())
while t > 0:
	bandera = False
	(a, b) = map(int, input().split())
	value = 0
	if a == b:
		print(value)
		t -= 1
		continue
	if a < b:
		value = 0
		c = 0
		while a < b:
			a *= 2
			c += 1
			if a == b:
				if c >= 3:
					if c % 3 == 0:
						value += c // 3
						c = 0
					else:
						value += c // 3
						c %= 3
				if c >= 2:
					if c % 2 == 0:
						value += c // 2
						c = 0
					else:
						value += c // 2
						c %= 2
				value += c
			if a > b:
				print(-1)
				value = -1
				bandera = True
				break
	elif a > b:
		value = 0
		c = 0
		while a > b:
			if a % 2 == 0:
				a //= 2
				c += 1
			elif a != b:
				value = -1
				break
			if a == b:
				if c >= 3:
					if c % 3 == 0:
						value += c // 3
						c = 0
					else:
						value += c // 3
						c %= 3
				if c >= 2:
					if c % 2 == 0:
						value += c // 2
						c = 0
					else:
						value += c // 2
						c %= 2
				value += c
			if a < b:
				print(-1)
				value = -1
				bandera = True
				break
	if not bandera:
		print(value)
	t -= 1


import math
pi = math.acos(-1)
T = int(input())
for _ in range(T):
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	cnt = 0
	while a <= b:
		if 8 * a <= b:
			cnt = cnt + 1
			a = 8 * a
		elif 4 * a <= b:
			cnt = cnt + 1
			a = 4 * a
		elif 2 * a <= b:
			cnt = cnt + 1
			a = 2 * a
		elif a == b:
			print(cnt)
			break
		else:
			print(-1)
			break


def log(n: int) -> int:
	ans = 0
	while n % 2 == 0:
		ans += 1
		n >>= 1
	if n == 1:
		return ans
	else:
		return -1
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a >= b and a % b == 0:
		z = a // b
		l = log(z)
		if l != -1:
			ans = l // 3
			l %= 3
			ans += l // 2
			l %= 2
			ans += l
			print(ans)
		else:
			print(-1)
	elif b > a and b % a == 0:
		z = b // a
		l = log(z)
		if l != -1:
			ans = l // 3
			l %= 3
			ans += l // 2
			l %= 2
			ans += l
			print(ans)
		else:
			print(-1)
	else:
		print(-1)


from math import ceil

def fn(n):
	c = 0
	while n % 2 == 0:
		n = n // 2
		c += 1
	return [n, c]
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
		continue
	n1 = fn(a)
	n2 = fn(b)
	if n1[0] != n2[0]:
		print(-1)
	else:
		di = ceil(abs(n1[1] - n2[1]) / 3)
		print(di)


for _ in range(int(input())):
	(a, b) = [int(x) for x in input().split()]
	(a, b) = sorted([a, b])
	turns = 0
	while a < b:
		turns += 1
		a *= 8
	if a == b or a // 2 == b or a // 4 == b:
		print(turns)
	else:
		print(-1)


import math
import sys
import collections
from collections import defaultdict
from sys import stdin, stdout
sys.setrecursionlimit(10 ** 9)
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
	elif a > b:
		if a % b != 0:
			print(-1)
		else:
			temp = a // b
			a = [8, 4, 2]
			cnt = 0
			while temp != 1:
				flag = 0
				for i in range(3):
					if temp % a[i] == 0:
						flag = 1
						cnt += 1
						temp = temp // a[i]
						break
				if flag == 0:
					break
			if flag == 0:
				print(-1)
			else:
				print(cnt)
	elif b % a != 0:
		print(-1)
	else:
		temp = b // a
		a = [8, 4, 2]
		cnt = 0
		while temp != 1:
			flag = 0
			for i in range(3):
				if temp % a[i] == 0:
					flag = 1
					cnt += 1
					temp = temp // a[i]
					break
			if flag == 0:
				break
		if flag == 0:
			print(-1)
		else:
			print(cnt)


t = int(input())
for T in range(t):
	(a, b) = map(int, input().split())
	if a == b:
		print(0)
		continue
	elif a > b:
		if a % b == 0 and a // b % 2 == 1:
			print(-1)
			continue
		count_a = 0
		count_b = 0
		while a > 0:
			if a % 8 == 0 and a // 8 >= b:
				count_a += 1
				a = a // 8
				continue
			elif a % 4 == 0 and a // 4 >= b:
				a = a // 4
				count_a += 1
			elif a % 2 == 0 and a // 2 >= b:
				a = a // 2
				count_a += 1
			else:
				break
		if a == b:
			print(count_a)
		else:
			print(-1)
	elif a < b:
		if b % a == 0 and b // a % 2 == 1:
			print(-1)
			continue
		count_a = 0
		count_b = 0
		while b > 0:
			if b % 8 == 0 and b // 8 >= a:
				b = b // 8
				count_b += 1
				continue
			elif b % 4 == 0 and b // 4 >= a:
				b = b // 4
				count_b += 1
			elif b % 2 == 0 and b // 2 >= a:
				b = b // 2
				count_b += 1
			else:
				break
		if a == b:
			print(count_b)
		else:
			print(-1)


t = int(input())

def fun(a, b):
	flag = 0
	if a > b:
		ans = 0
		while b < a:
			if b * 8 <= a:
				ans += 1
				b *= 8
			elif b * 4 <= a:
				ans += 1
				b *= 4
			else:
				ans += 1
				b *= 2
		if a == b:
			print(ans)
		else:
			print(-1)
	else:
		ans = 0
		flag = 0
		while a < b:
			if a * 8 <= b:
				a *= 8
				ans += 1
			elif a * 4 <= b:
				ans += 1
				a *= 4
			else:
				a *= 2
				ans += 1
		if a == b:
			print(ans)
		else:
			print(-1)
while t:
	t -= 1
	(a, b) = map(int, input().split())
	fun(a, b)