You are given an integer $n$.

You can perform any of the following operations with this number an arbitrary (possibly, zero) number of times:   Replace $n$ with $\frac{n}{2}$ if $n$ is divisible by $2$;  Replace $n$ with $\frac{2n}{3}$ if $n$ is divisible by $3$;  Replace $n$ with $\frac{4n}{5}$ if $n$ is divisible by $5$. 

For example, you can replace $30$ with $15$ using the first operation, with $20$ using the second operation or with $24$ using the third operation.

Your task is to find the minimum number of moves required to obtain $1$ from $n$ or say that it is impossible to do it.

You have to answer $q$ independent queries.


-----Input-----

The first line of the input contains one integer $q$ ($1 \le q \le 1000$) — the number of queries.

The next $q$ lines contain the queries. For each query you are given the integer number $n$ ($1 \le n \le 10^{18}$).


-----Output-----

Print the answer for each query on a new line. If it is impossible to obtain $1$ from $n$, print -1. Otherwise, print the minimum number of moves required to do it.


-----Example-----
Input
7
1
10
25
30
14
27
1000000000000000000

Output
0
4
6
6
-1
6
72

Difficulty: EASY
Tags: Complete search

Implementation

Greedy algorithms
Skill types: Complete search

Greedy algorithms

Starter code:

Solutions:
for _ in range(int(input())):
	c = 0
	n = int(input())
	ans = 1
	while n > 1:
		c += 1
		if n % 2 == 0:
			n = n // 2
		elif n % 3 == 0:
			n = 2 * n // 3
		elif n % 5 == 0:
			n = 4 * n // 5
		else:
			ans = 0
			break
	if ans == 0:
		print(-1)
	else:
		print(c)


t = int(input())
for _ in range(t):
	n = int(input())
	c = 0
	while n != 1:
		if n % 2:
			if n % 3 and n % 5:
				break
		if n % 2 == 0:
			n //= 2
			c += 1
		elif n % 3 == 0:
			n //= 3
			c += 2
		else:
			n //= 5
			c += 3
	if n != 1:
		print(-1)
	else:
		print(c)


q = int(input())
while q:
	n = int(input())
	a = 0
	while n % 2 == 0:
		n = n // 2
		a += 1
	b = 0
	while n % 3 == 0:
		n = n // 3
		b += 1
	c = 0
	while n % 5 == 0:
		n = n // 5
		c += 1
	if n == 1:
		print(a + 2 * b + 3 * c)
	else:
		print(-1)
	q -= 1


fx = int(input())
for i in range(fx):
	n = int(input())
	a = 0
	while n % 2 == 0:
		n //= 2
		a += 1
	while n % 3 == 0:
		n //= 3
		a += 2
	while n % 5 == 0:
		n //= 5
		a += 3
	if n == 1:
		print(a)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	s = 0
	while n != 1:
		if n % 2 == 0:
			n = n // 2
			s = s + 1
		elif n % 3 == 0:
			n = 2 * n // 3
			s = s + 1
		elif n % 5 == 0:
			n = 4 * n // 5
			s = s + 1
		else:
			s = -1
			break
	print(s)


q = int(input())
for i in range(q):
	n = int(input())
	count = 0
	while n % 2 == 0 or n % 3 == 0 or n % 5 == 0:
		if n % 2 == 0:
			n = n // 2
			count += 1
		if n % 3 == 0:
			n = 2 * n // 3
			count += 1
		if n % 5 == 0:
			n = 4 * n // 5
			count += 1
	if n == 1:
		print(count)
	else:
		print(-1)


q = int(input())
while q > 0:
	q -= 1
	n = int(input())
	op = 0
	while True:
		op += 1
		if n % 2 == 0:
			n = n // 2
		elif n % 3 == 0:
			n = 2 * n // 3
		elif n % 5 == 0:
			n = 4 * n // 5
		else:
			op -= 1
			break
	if n == 1:
		print(op)
	else:
		print(-1)


tc = int(input())
while tc > 0:
	n = int(input())
	cnt = 0
	imp = False
	while n != 1:
		if n % 2 == 0:
			cnt += 1
			n //= 2
		elif n % 3 == 0:
			cnt += 1
			n //= 3
			n *= 2
		elif n % 5 == 0:
			cnt += 1
			n //= 5
			n *= 4
		else:
			imp = True
			break
	if imp:
		print(-1)
	else:
		print(cnt)
	tc -= 1


for t in range(int(input())):
	n = int(input())
	nop = 0
	while n != 1:
		if n % 2 == 0:
			n = n // 2
			nop += 1
		elif n % 3 == 0:
			n = n // 3
			nop += 2
		elif n % 5 == 0:
			n = n // 5
			nop += 3
		else:
			nop = -1
			break
	print(nop)


import sys
from math import sqrt, floor, factorial
from collections import deque, Counter
inp = sys.stdin.readline
read = lambda : list(map(int, inp().strip().split()))

def solve():
	ans = ''
	for _ in range(int(inp())):
		n = int(inp())
		s = 0
		tem = n
		dic = {2: 1, 3: 2, 5: 3}
		for i in [2, 3, 5]:
			while n % i == 0:
				n //= i
				s += dic[i]
		ans += str([-1, s][n == 1]) + '\n'
	print(ans)
solve()


import sys
input = sys.stdin.readline
n = int(input())
for i in range(0, n):
	cnt = 0
	num = int(input())
	if num == 1:
		print(cnt)
		continue
	while True:
		if num % 2 != 0 and num % 3 != 0 and (num % 5 != 0):
			print(-1)
			break
		if num % 2 == 0:
			num = num // 2
			cnt += 1
		elif num % 3 == 0:
			num = 2 * num // 3
			cnt += 1
		elif num % 5 == 0:
			num = 4 * num // 5
			cnt += 1
		if num == 1:
			print(cnt)
			break


def pm(n, v):
	rem = n
	cnt = 0
	while rem > 1 and rem % v == 0:
		rem //= v
		cnt += 1
	return (rem, cnt)

def calc(n):
	(r, n2) = pm(n, 2)
	(r, n3) = pm(r, 3)
	(r, n5) = pm(r, 5)
	if r != 1:
		return -1
	else:
		res = n2
		if n3:
			res += n3 * 2
		if n5:
			res += n5 * 3
		return res
for _ in range(int(input())):
	print(calc(int(input())))


n = int(input())
for k in range(n):
	num = int(input())
	count = 0
	while num != 1:
		count += 1
		if num % 2 == 0:
			num = num // 2
		elif num % 3 == 0:
			num = 2 * num // 3
		elif num % 5 == 0:
			num = 4 * num // 5
		else:
			count = -1
			break
	print(count)


q = int(input())
for i in range(q):
	c = 0
	a = int(input())
	if a == 1:
		print(0)
	else:
		while a != 1:
			if a % 2 == 0:
				a = a // 2
				c += 1
			elif a % 3 == 0:
				a = 2 * (a // 3)
				c += 1
			elif a % 5 == 0:
				a = 4 * (a // 5)
				c += 1
			else:
				c = -1
				break
		print(c)


from sys import stdin, stdout
from collections import *
from math import gcd, ceil, floor

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

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

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

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

def pr(n):
	return stdout.write(str(n) + '\n')
mod = 1000000007
INF = float('inf')
Y = 'YES'
N = 'NO'

def solve(x, p=0):
	if x == 1:
		return p
	if x == 2:
		return 1 + p
	if x % 2 == 0:
		return solve(x // 2, p + 1)
	if x % 3 == 0:
		return solve(2 * (x // 3), p + 1)
	if x % 5 == 0:
		return solve(4 * (x // 5), p + 1)
	return -1
for test in range(int(input())):
	n = int(input())
	print(solve(n))


def Divide(n):
	times = 0
	while n != 1:
		if n % 2 == 0:
			n = n // 2
		elif n % 3 == 0:
			n = 2 * n // 3
		elif n % 5 == 0:
			n = 4 * n // 5
		else:
			print(-1)
			return
		times += 1
	print(times)
for i in range(int(input())):
	Divide(int(input()))


q = int(input())
INF = 10 ** 10
for x in range(q):
	n = int(input())
	op = 0
	while n > 1:
		if n % 2 == 0:
			n //= 2
		elif n % 3 == 0:
			n = 2 * n // 3
		elif n % 5 == 0:
			n = 4 * n // 5
		else:
			break
		op += 1
	if n == 1:
		print(op)
	else:
		print(-1)


q = int(input())
for i in range(q):
	o = 0
	n = int(input())
	alpha = 0
	beta = 0
	gamma = 0
	while n != 1 and (n % 2 == 0 or n % 3 == 0 or n % 5 == 0):
		if n % 2 == 0:
			alpha += 1
			n //= 2
		if n % 3 == 0:
			beta += 1
			n //= 3
		if n % 5 == 0:
			gamma += 1
			n //= 5
	if n != 1:
		print(-1)
	else:
		print(alpha + 2 * beta + 3 * gamma)


for i in range(int(input())):
	n = int(input())
	c = 0
	f = 0
	while n != 1:
		if n % 5 == 0:
			c += 1
			n = 4 * n // 5
		elif n % 3 == 0:
			c += 1
			n = 2 * n // 3
		elif n % 2 == 0:
			c += 1
			n = n // 2
		else:
			f = 1
			break
	if f == 1:
		print(-1)
	else:
		print(c)


t = int(input())
l = []
while t:
	sum = 0
	n = int(input())
	while n % 2 == 0:
		sum += 1
		n = n // 2
	while n % 3 == 0:
		sum += 2
		n = n // 3
	while n % 5 == 0:
		n = n // 5
		sum += 3
	if n != 1:
		print(-1)
	else:
		print(sum)
	t -= 1


def divide(n):
	(a, b, c) = (0, 0, 0)
	while True:
		if n % 2 == 0:
			a += 1
			n = n // 2
		else:
			break
	while True:
		if n % 3 == 0:
			b += 1
			n = n // 3
		else:
			break
	while True:
		if n % 5 == 0:
			c += 1
			n = n // 5
		else:
			break
	if n > 1:
		return -1
	return a + 2 * b + 3 * c
q = int(input())
for _ in range(q):
	n = int(input())
	print(divide(n))


def has_not_235(n):
	while n % 2 == 0:
		n //= 2
	while n % 3 == 0:
		n //= 3
	while n % 5 == 0:
		n //= 5
	return n > 1

def check_235(n):
	ret = 0
	while n > 1:
		if n & 1 == 0:
			n //= 2
			ret += 1
		if n % 3 == 0:
			n //= 3
			ret += 2
		if n % 5 == 0:
			n //= 5
			ret += 3
	return ret

def dit(n):
	if has_not_235(n):
		return -1
	return check_235(n)
for _ in range(int(input())):
	n = int(input())
	print(dit(n))


s = int(input())
for i in range(s):
	n = int(input())
	t = 0
	f = n
	for j in range(f):
		if n == 1:
			print(t)
			break
		elif 4 * n % 5 == 0:
			n = 4 * n // 5
			t += 1
		elif 2 * n % 3 == 0:
			n = 2 * n // 3
			t += 1
		elif n % 2 == 0:
			n = n // 2
			t += 1
		elif 4 * n % 5 != 0 and n * 2 % 3 != 0 and (n % 2 != 0):
			print('-1')
			break


x = int(input())
for i in range(x):
	t = int(input())
	k = 0
	while True:
		if t % 2 == 0:
			t = t // 2
			k = k + 1
		elif t % 3 == 0:
			t = t // 3
			k = k + 2
		elif t % 5 == 0:
			t = t // 5
			k = k + 3
		elif t == 1:
			print(k)
			break
		else:
			print(-1)
			break


t = int(input())
for q in range(t):
	n = int(input())
	ct = 0
	while n > 1:
		if n % 2 == 0:
			n = n // 2
		elif n % 3 == 0:
			n = 2 * (n // 3)
		elif n % 5 == 0:
			n = 4 * (n // 5)
		else:
			break
		ct += 1
	if n == 1:
		print(ct)
	else:
		print(-1)


def funny(n):
	r = 0
	while n != 1:
		if n % 2 == 0:
			n //= 2
		elif n % 3 == 0:
			n = 2 * n // 3
		elif n % 5 == 0:
			n = 4 * n // 5
		else:
			break
		r += 1
	return r if n == 1 else -1
x = int(input())
for i in range(x):
	print(funny(int(input())))


t = int(input())
for _ in range(t):
	n = int(input())
	count = 0
	while True:
		if n == 1:
			break
		if n % 2 == 0:
			n = n // 2
		elif n % 3 == 0:
			n = 2 * n // 3
		elif n % 5 == 0:
			n = 4 * n // 5
		else:
			count = -1
			break
		count += 1
	print(count)


q = int(input())
for _ in range(q):
	n = int(input())
	powOf2 = 0
	powOf3 = 0
	powOf5 = 0
	while n != 1:
		if n % 2 == 0:
			n = n // 2
			powOf2 += 1
		elif n % 3 == 0:
			n = n // 3
			powOf3 += 1
		elif n % 5 == 0:
			n = n // 5
			powOf5 += 1
		else:
			break
	if n != 1:
		print(-1)
	else:
		print(powOf2 + 2 * powOf3 + 3 * powOf5)


for i in range(int(input())):
	mov = 0
	num = int(input())
	while num != 1:
		if num % 2 == 0:
			num >>= 1
			mov += 1
		elif num % 3 == 0:
			num //= 3
			num <<= 1
			mov += 1
		elif num % 5 == 0:
			num //= 5
			num <<= 2
			mov += 1
		else:
			mov = -1
			break
	print(mov)


def f(n):
	a = 0
	while n % 5 == 0:
		n //= 5
		n *= 4
		a += 1
	while n % 3 == 0:
		n //= 3
		n *= 2
		a += 1
	while n % 2 == 0:
		n //= 2
		a += 1
	if n != 1:
		return -1
	return a
q = int(input())
for i in range(q):
	n = int(input())
	print(f(n))


def fn(a):
	cnt = 0
	while a != 1:
		if a % 2 != 0 and a % 3 != 0 and (a % 5 != 0):
			return -1
		elif a % 2 == 0:
			a = a // 2
			cnt += 1
		elif a % 3 == 0:
			a = 2 * (a // 3)
			cnt += 1
		elif a % 5 == 0:
			a = 4 * (a // 5)
			cnt += 1
	return cnt
n = int(input())
for _ in range(n):
	a = int(input())
	res = fn(a)
	print(res)


from math import inf

def solve(n, m):
	if n == 1:
		return m
	if n < 1:
		return inf
	(a, b, c) = (inf, inf, inf)
	if n % 2 == 0:
		a = solve(n // 2, m + 1)
	elif n % 3 == 0:
		b = solve(2 * n // 3, m + 1)
	elif n % 5 == 0:
		c = solve(4 * n // 5, m + 1)
	s = min(a, b, c)
	return s

def main():
	for _ in range(int(input())):
		n = int(input())
		s = solve(n, 0)
		if s == inf:
			print(-1)
		else:
			print(s)
main()


def factor(n, k):
	c = 0
	p = k
	while n % k == 0:
		c += 1
		k = p ** (c + 1)
	return c
q = int(input())
for i in range(q):
	n = int(input())
	if n == 1:
		print('0')
	else:
		r = 0
		a = factor(n, 2)
		b = factor(n, 3)
		c = factor(n, 5)
		if 2 ** a * 3 ** b * 5 ** c != n:
			print('-1')
		else:
			print(a + 2 * b + 3 * c)


q = int(input())
for i in range(q):
	num = int(input())
	bad = False
	ans = 0
	while num != 1 and (not bad):
		if num % 2 == 0:
			num //= 2
		elif num % 3 == 0:
			num = num // 3 * 2
		elif num % 5 == 0:
			num = num // 5 * 4
		else:
			bad = True
		ans += 1
	if bad:
		print('-1')
	else:
		print(ans)


for TT in range(1, int(input()) + 1):
	n = int(input())
	res = 0
	while n > 1:
		check = False
		for d in (2, 3, 5):
			if n % d == 0:
				n //= d
				n *= d - 1
				check = True
				break
		if not check:
			res = -1
			break
		res += 1
	print(res)


a = []
for i in range(int(input())):
	a.append(int(input()))
for i in a:
	s = 0
	while True:
		if i == 1:
			print(s)
			break
		elif i % 2 == 0:
			i //= 2
			s += 1
		elif i % 3 == 0:
			i = i // 3 * 2
			s += 1
		elif i % 5 == 0:
			i = i // 5 * 4
			s += 1
		else:
			print(-1)
			break


t = int(input())
for k in range(t):
	n = int(input())
	(cnt_2, n_2) = (0, n)
	(cnt_3, n_3) = (0, n)
	(cnt_5, n_5) = (0, n)
	while n_2 % 2 == 0:
		cnt_2 += 1
		n_2 //= 2
	while n_3 % 3 == 0:
		cnt_3 += 1
		n_3 //= 3
	while n_5 % 5 == 0:
		cnt_5 += 1
		n_5 //= 5
	if 2 ** cnt_2 * 3 ** cnt_3 * 5 ** cnt_5 != n:
		ans = -1
	else:
		ans = cnt_2 + 2 * cnt_3 + 3 * cnt_5
	print(ans)


def getAns(n):
	if n == 1:
		return 0
	if n % 2 == 0:
		return getAns(n // 2) + 1
	if n % 3 == 0:
		return getAns(2 * n // 3) + 1
	if n % 5 == 0:
		return getAns(4 * n // 5) + 1
	else:
		return -9999999999999999999999999
for loop in range(int(input())):
	a = getAns(int(input()))
	if a < 0:
		print(-1)
	else:
		print(a)


t = int(input())
while t:
	t -= 1
	n = int(input())
	if n == 1:
		print(0)
	else:
		ans = 0
		c5 = 0
		c3 = 0
		while 1:
			if n % 5 == 0:
				n = n // 5
				c5 += 1
				ans += 1
			if n % 3 == 0:
				n = n // 3
				c3 += 1
				ans += 1
			if n % 2 == 0:
				n = n // 2
				ans += 1
			if n % 5 and n % 3 and n % 2:
				break
		if n == 1:
			print(ans + c3 + 2 * c5)
		else:
			print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	c = 0
	while n != 1:
		if n % 2 == 0:
			n = n // 2
			c += 1
		elif n % 3 == 0:
			n = 2 * n
			n = n // 3
			c += 1
		elif n % 5 == 0:
			n = 4 * n
			n = n // 5
			c += 1
		elif n % 2 != 0 and n % 3 != 0 and (n % 5 != 0):
			c = -1
			break
	print(c)


q = int(input())
for i in range(q):
	n = int(input())
	count = 0
	flag = True
	while n != 1:
		if n % 2 == 0:
			n = n // 2
			count += 1
		elif n % 3 == 0:
			n = 2 * n // 3
			count += 1
		elif n % 5 == 0:
			n = 4 * n // 5
			count += 1
		else:
			print(-1)
			flag = False
			break
	if flag:
		print(count)


def f(n, c):
	if n == 1 or n == -1:
		return c
	if n % 2 == 0:
		return f(n // 2, c + 1)
	elif n % 3 == 0:
		return f(2 * n // 3, c + 1)
	elif n % 5 == 0:
		return f(4 * n // 5, c + 1)
	else:
		return -1

def main():
	t = input()
	for _ in range(int(t)):
		n = int(input())
		c = 0
		print(f(n, 0))
main()


import sys
k = int(sys.stdin.readline())
for i in range(k):
	n = int(sys.stdin.readline())
	(c1, c3, c5) = (0, 0, 0)
	while n % 2 == 0:
		c1 += 1
		n = n // 2
	while n % 3 == 0:
		c3 += 1
		n = n // 3
	while n % 5 == 0:
		c5 += 1
		n = n // 5
	if n != 1:
		print('-1')
	else:
		print(c1 + 2 * c3 + 3 * c5)


def div_cnt(n, d):
	cnt = 0
	while n % d == 0:
		n //= d
		cnt += 1
	return cnt
nums = {2: 1, 3: 2, 5: 3}
for _ in range(int(input())):
	n = int(input())
	total = 0
	for d in nums:
		cnt = div_cnt(n, d)
		n //= d ** cnt
		total += cnt * nums[d]
	print(-1 if n > 1 else total)


def check(a):
	answ = 0
	while a % 3 == 0:
		answ += 1
		a = a // 3 * 2
	while a % 5 == 0:
		answ += 1
		a = a // 5 * 4
	while a % 2 == 0:
		answ += 1
		a = a // 2
	if a != 1:
		return -1
	return answ
t = int(input())
for i in range(t):
	x = int(input())
	print(check(x))


import decimal
D = decimal.Decimal

def answer():
	n = D(int(input()))
	while n:
		a = D(int(input()))
		ans = 0
		while a >= 1:
			if D(a % 3) == 0:
				a = D(2 * a)
				a = D(a / 3)
				ans += 1
			elif D(a % 5) == 0:
				a = D(a * 4)
				a = D(a / 5)
				ans += 1
			elif a % 2 == 0:
				a = D(a / 2)
				ans += 1
			else:
				break
		if a != 1:
			print(-1)
		else:
			print(ans)
		n -= 1
answer()


from math import gcd
for _ in range(int(input())):
	n = int(input())
	f = True
	count = 0
	while n != 1:
		if n % 2 == 0:
			n = n // 2
		elif n % 3 == 0:
			n = 2 * (n // 3)
		elif n % 5 == 0:
			n = 4 * (n // 5)
		else:
			f = False
			break
		count += 1
	if f:
		print(count)
	else:
		print(-1)


def divide(n):
	pasos = 0
	while n > 1:
		if n % 2 == 0:
			n = n // 2
			pasos += 1
		elif n % 3 == 0:
			n = 2 * n // 3
			pasos += 1
		elif n % 5 == 0:
			n = 4 * n // 5
			pasos += 1
		else:
			return -1
	return pasos
q = int(input())
lista = []
for i in range(q):
	n = int(input())
	lista.append(n)
for n in lista:
	print(divide(n))


def check(n):
	c = 0
	while n > 1:
		c += 1
		(d, r) = divmod(n, 2)
		if r == 0:
			n = d
			continue
		(d, r) = divmod(n, 3)
		if r == 0:
			n = 2 * d
			continue
		(d, r) = divmod(n, 5)
		if r == 0:
			n = 4 * d
			continue
		return
	return c
q = int(input())
for _ in range(q):
	n = int(input())
	c = check(n)
	print(c if c is not None else -1)


t = int(input())
while t:
	n = int(input())
	done = False
	count = 0
	while n != 1 and (not done):
		if n % 5 == 0:
			n = 4 * n // 5
		elif n % 3 == 0:
			n = 2 * n // 3
		elif n % 2 == 0:
			n = n // 2
		else:
			done = True
		count += 1
	t -= 1
	if n == 1:
		print(count)
	else:
		print(-1)


def solve(n):
	if n == 1:
		return 0
	cnt = 0
	while n > 0:
		if n == 1:
			return cnt
		if n % 2 != 0 and n % 3 != 0 and (n % 5 != 0):
			return -1
		while n % 2 == 0 and n > 0:
			n //= 2
			cnt += 1
		if n % 3 == 0:
			n = 2 * n // 3
			cnt += 1
		if n % 5 == 0:
			n = 4 * n // 5
			cnt += 1
	return cnt
res = []
t = int(input())
while t:
	n = int(input())
	res.append(solve(n))
	t -= 1
for r in res:
	print(r)


q = int(input())
for iteration in range(0, q):
	n = int(input())
	a = 0
	b = 0
	c = 0
	while n % 2 == 0:
		n //= 2
		a += 1
	while n % 3 == 0:
		n //= 3
		b += 1
	while n % 5 == 0:
		n //= 5
		c += 1
	if n != 1:
		print(-1)
	else:
		print(a + 2 * b + 3 * c)


def func():
	q = int(input())
	for i in range(q):
		n = int(input())
		counter = 0
		while n % 5 == 0:
			n //= 5
			counter += 3
		while n % 3 == 0:
			n //= 3
			counter += 2
		while n % 2 == 0:
			n //= 2
			counter += 1
		if n == 1:
			print(counter)
		else:
			print(-1)
func()


for _ in range(int(input())):
	n = int(input())
	f = 1
	cnt = 0
	while n > 1:
		if n % 2 == 0:
			n //= 2
			cnt += 1
		elif n % 3 == 0:
			n = n // 3 * 2
			cnt += 1
		elif n % 5 == 0:
			n = n // 5 * 4
			cnt += 1
		else:
			break
	if n != 1:
		f = 0
	if f:
		print(cnt)
	else:
		print(-1)


q = int(input())
for i in range(q):
	n = int(input())
	count1 = 0
	count2 = 0
	count3 = 0
	if n == 1:
		print(0)
	else:
		flag = 0
		while n != 1:
			if n % 2 != 0 and n % 3 != 0 and (n % 5 != 0):
				flag = 1
				break
			if n % 2 == 0:
				while n != 1 and n % 2 == 0:
					count1 = count1 + 1
					n = n // 2
			if n % 3 == 0:
				while n != 1 and n % 3 == 0:
					count2 = count2 + 1
					n = n // 3
			if n % 5 == 0:
				while n != 1 and n % 5 == 0:
					count3 = count3 + 1
					n = n // 5
		if flag == 1:
			print(-1)
		else:
			ans = count1 + count2 + count2 + 2 * count3 + count3
			print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	(a, b, c) = (0, 0, 0)
	i = 1
	while n != 1:
		if n % 2 ** i == 0:
			a = i
		else:
			break
		i += 1
	n = n // 2 ** a
	i = 1
	while n != 1:
		if n % 3 ** i == 0:
			b = i
		else:
			break
		i += 1
	n = n // 3 ** b
	i = 1
	while n != 1:
		if n % 5 ** i == 0:
			c = i
		else:
			break
		i += 1
	n = n // 5 ** c
	if n == 1:
		print(a + 2 * b + 3 * c)
	else:
		print(-1)


def solve(n):
	ans = 0
	while n != 1:
		if n % 2 == 0:
			n = n // 2
		elif n % 3 == 0:
			n = n // 3 * 2
		elif n % 5 == 0:
			n = n // 5 * 4
		else:
			return -1
		ans += 1
	return ans
for _ in range(int(input())):
	n = int(input())
	print(solve(n))


for q in range(int(input())):
	n = int(input())
	res = 0
	while n % 2 == 0 or n % 3 == 0 or n % 5 == 0:
		if n % 2 == 0:
			n //= 2
			res += 1
		elif n % 3 == 0:
			n //= 3
			res += 2
		else:
			n //= 5
			res += 3
	print(res if n == 1 else -1)


def count_steps(x):
	flag = True
	cs = 0
	while flag:
		if x % 2 == 0:
			x = x // 2
			cs = cs + 1
		elif x % 3 == 0:
			x = 2 * x // 3
			cs += 1
		elif x % 5 == 0:
			x = 4 * x // 5
			cs += 1
		else:
			flag = False
	if x == 1:
		return cs
	else:
		return -1
T = int(input())
for i in range(T):
	x = int(input())
	print(count_steps(x))


for t in range(int(input())):
	c = 0
	num = int(input())
	while num % 2 == 0:
		num //= 2
		c += 1
	while num % 3 == 0:
		num //= 3
		c += 2
	while num % 5 == 0:
		num //= 5
		c += 3
	if num == 1:
		print(c)
	else:
		print(-1)


c = 0
counter = []
x = int(input())
for i in range(x):
	n = int(input())
	if n == 1:
		c = 0
	while n != 1:
		if n % 2 == 0:
			n //= 2
			c += 1
		elif n % 3 == 0:
			n = 2 * n // 3
			c += 1
		elif n % 5 == 0:
			n = 4 * n // 5
			c += 1
		else:
			c = -1
			break
	counter.append(c)
	c = 0
for i in counter:
	print(i)


q = int(input())
for i in range(q):
	w = int(input())
	n = 0
	for i in (5, 3, 2):
		if i == 5:
			m = 4
		elif i == 3:
			m = 2
		else:
			m = 1
		while w % i == 0:
			w = w * m // i
			n += 1
	if w == 1:
		print(n)
	else:
		print(-1)


N = int(input())
L = []
for i in range(N):
	L.append(int(input()))
for i in range(N):
	n = L.pop(0)
	counter = 0
	while n != 1 and n != -1:
		counter += 1
		s = list(str(n))
		e = s[len(s) - 1]
		if int(e) % 2 == 0:
			n = n // 2
			continue
		if sum([int(x) for x in s]) % 3 == 0:
			n = n // 3 * 2
			continue
		if int(e) % 5 == 0:
			n = n // 5 * 4
			continue
		n = -1
	if n == -1:
		print(-1)
	else:
		print(counter)


t = int(input())
for i in range(t):
	a = int(input())
	ans = 0
	key = True
	while a != 1:
		if a % 2 == 0:
			a //= 2
			ans += 1
		elif a % 3 == 0:
			a = a // 3 * 2
			ans += 1
		elif a % 5 == 0:
			a = a // 5 * 4
			ans += 1
		else:
			print(-1)
			key = False
			break
	if key:
		print(ans)


for _ in range(int(input())):
	n = int(input())
	a = 0
	while not n % 5:
		a += 3
		n = n // 5
	while not n % 3:
		a += 2
		n = n // 3
	while not n % 2:
		a += 1
		n = n // 2
	if n != 1:
		print('-1')
	else:
		print(a)


import math as mt
import sys, string, bisect
input = sys.stdin.readline
from collections import deque, 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()
for _ in range(t):
	n = I()
	a = 0
	d = 1
	while n != 1:
		if n % 2 == 0:
			n = n // 2
			a += 1
		elif n % 3 == 0:
			n //= 3
			n *= 2
			a += 1
		elif n % 5 == 0:
			n //= 5
			n *= 4
			a += 1
		else:
			print(-1)
			d = 0
			break
	if d:
		print(a)


a = int(input())
i = 0
while i < a:
	op = 0
	n = int(input())
	if n <= 0:
		op = -1
	else:
		while n != 1:
			if n % 5 == 0:
				op += 1
				n = 4 * n // 5
			elif n % 3 == 0:
				op += 1
				n = 2 * n // 3
			elif n % 2 == 0:
				op += 1
				n = n // 2
			else:
				op = -1
				break
	print(op)
	i += 1


q = int(input())
for qq in range(0, q):
	n = int(input())
	counter = 0
	while n != 1:
		counter = counter + 1
		if n % 2 == 0:
			n = n // 2
		elif n % 3 == 0:
			n = 2 * n // 3
		elif n % 5 == 0:
			n = 4 * n // 5
		else:
			counter = -1
			break
	print(str(counter))


ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(mi())
si = lambda : input()
msi = lambda : map(int, stdin.readline().split())
lsi = lambda : list(msi())
t = ii()
for _ in range(t):
	n = ii()
	count = 0
	while n % 5 == 0:
		n = n // 5
		count += 3
	while n % 3 == 0:
		n = n // 3
		count += 2
	while n % 2 == 0:
		n = n // 2
		count += 1
	if n != 1:
		print(-1)
	else:
		print(count)


RI = lambda : [int(x) for x in input().strip().split()]
rw = lambda : input().strip().split()
from collections import defaultdict as df
t = int(input())
for i in range(t):
	n = int(input())
	ans = 0
	while n % 2 == 0:
		n //= 2
		ans += 1
	while n % 3 == 0:
		n //= 3
		ans += 2
	while n % 5 == 0:
		n //= 5
		ans += 3
	if n == 1:
		print(ans)
	else:
		print(-1)


from sys import stdin
q = int(stdin.readline().rstrip())
while q > 0:
	n = int(stdin.readline().rstrip())
	flag = 0
	c = 0
	while n != 1:
		if n % 2 == 0:
			n //= 2
			c += 1
		elif n % 3 == 0:
			n = 2 * n // 3
			c += 1
		elif n % 5 == 0:
			n = 4 * n // 5
			c += 1
		else:
			flag = 1
			break
	if flag == 1:
		print(-1)
	else:
		print(c)
	q -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	r = 0
	while n % 2 == 0:
		r += 1
		n //= 2
	while n % 3 == 0:
		r += 2
		n //= 3
	while n % 5 == 0:
		r += 3
		n //= 5
	print(r if n == 1 else -1)


q = int(input())
for z in range(q):
	n = int(input())
	count = 0
	if n == 1:
		print(count)
		continue
	while n % 5 == 0:
		n = 4 * n // 5
		count += 1
		if n == 1:
			print(count)
			continue
	while n % 3 == 0:
		n = 2 * n // 3
		count += 1
		if n == 1:
			print(count)
			continue
	while n % 2 == 0:
		n = n // 2
		count += 1
		if n == 1:
			print(count)
			continue
	if n != 1:
		print(-1)


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

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def power(x, p, m):
	res = 1
	while p:
		if p & 1:
			res = res * x % m
		x = x * x % m
		p >>= 1
	return res

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

def lcm(num1, num2):
	return num1 * num2 // gcd(num1, num2)

def binaryToDecimal(n):
	return int(n, 2)

def main():
	dic = {}
	for i in range(0, 65):
		dic[2 ** i] = i
	for _ in range(int(input())):
		n = int(input())
		ans = 0
		counter = 0
		while 1:
			if n in dic:
				ans += dic[n]
				break
			if n % 2 == 0:
				n = n // 2
				ans += 1
			elif n % 3 == 0:
				n = 2 * n // 3
				ans += 1
			elif n % 5 == 0:
				n = 4 * n // 5
				ans += 1
			else:
				counter = 1
				break
		if counter:
			print(-1)
		else:
			print(ans)
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 fun2(n):
	return n // 2

def fun3(n):
	return 2 * n // 3

def fun5(n):
	return 4 * n // 5
for _ in range(int(input())):
	N = int(input())
	cnt = 0
	while N > 1:
		if N % 5 == 0:
			N = fun5(N)
			cnt += 1
		if N % 3 == 0:
			N = fun3(N)
			cnt += 1
		if N % 2 == 0:
			N = fun2(N)
			cnt += 1
		if N % 2 != 0 and N % 3 != 0 and (N % 5 != 0) and (N != 1):
			cnt = -1
			break
	print(cnt)


for x in range(int(input())):
	a = int(input())
	f = 0
	if a == 1:
		print('0')
	else:
		b = 0
		while a != 1:
			if a % 2 == 0:
				a = a // 2
				b += 1
			elif a % 3 == 0:
				a = 2 * a // 3
				b += 1
			elif a % 5 == 0:
				a = 4 * a // 5
				b += 1
			else:
				print('-1')
				f = 1
				break
		if f == 0:
			print(b)


n = int(input())
for i in range(n):
	q = int(input())
	s = 0
	while q % 5 == 0:
		q = q // 5
		s += 3
	while q % 3 == 0:
		q = q // 3
		s += 2
	while q % 2 == 0:
		q = q // 2
		s += 1
	if q == 1:
		print(s)
	else:
		print(-1)


n = int(input())
q = []
for x in range(n):
	q.append(int(input()))
result = []

def replaceMethod(x):
	if x % 2 == 0:
		return x // 2
	elif x % 3 == 0:
		return 2 * x // 3
	elif x % 5 == 0:
		return 4 * x // 5
	else:
		return -1
for x in q:
	aux = x
	if x == 1:
		result.append(0)
	else:
		cont = 0
		while True:
			aux = replaceMethod(aux)
			cont += 1
			if aux == 1:
				result.append(cont)
				break
			elif aux == -1:
				result.append(-1)
				break
for x in result:
	print(x)


for _____ in range(int(input())):
	_ = int(input())
	ctx = 0
	while _ != 1:
		temp = _
		ctx += 1
		if _ % 2 == 0:
			_ = _ // 2
		elif _ % 3 == 0:
			_ = _ * 2 // 3
		elif _ % 5 == 0:
			_ = _ * 4 // 5
		if temp == _:
			ctx = -1
			break
	print(ctx)


def fun(n):
	c = 0
	while n != 1:
		if n % 2 == 0:
			n = n // 2
			c += 1
		elif n % 3 == 0:
			n = n // 3
			c += 2
		elif n % 5 == 0:
			n = n // 5
			c += 3
		else:
			return -1
	return c
t = int(input())
for _ in range(t):
	n = int(input())
	print(fun(n))


q = int(input())
for i in range(q):
	n = int(input())
	dic = dict()
	dic[2] = 0
	dic[3] = 0
	dic[5] = 0
	l = [2, 3, 5]
	for i in range(3):
		while n % l[i] == 0:
			n = n // l[i]
			dic[l[i]] += 1
	ans = dic[2] + 2 * dic[3] + 3 * dic[5]
	if n != 1:
		print(-1)
	else:
		print(ans)


for j in [0] * int(input()):
	n = int(input())
	ans = 0
	while n != 1:
		if n % 2 == 0:
			n = n // 2
			ans += 1
		elif n % 3 == 0:
			n = 2 * n // 3
			ans += 1
		elif n % 5 == 0:
			n = 4 * n // 5
			ans += 1
		else:
			break
	print(ans if n == 1 else -1)


import sys
q = int(sys.stdin.readline())
for _ in range(q):
	n = int(sys.stdin.readline())
	count = 0
	while n > 1:
		if n % 2 == 0:
			n //= 2
			count += 1
		elif n % 3 == 0:
			n //= 3
			n *= 2
			count += 1
		elif n % 5 == 0:
			n //= 5
			n *= 4
			count += 1
		else:
			count = -1
			break
	print(count)


number_of_queries = 0
number_n = []
minimum_number_of_moves = []

def Input():
	global number_of_queries, number_n, minmum_number_of_moves
	number_of_queries = int(input())
	for index in range(number_of_queries):
		number_n.append(int(input()))

def Minimum_number_of_moves(number):
	if number == 1:
		return 0
	else:
		number_of_twos = 0
		number_of_threes = 0
		number_of_fives = 0
		while number % 2 == 0:
			number_of_twos += 1
			number //= 2
		while number % 3 == 0:
			number_of_threes += 1
			number //= 3
		while number % 5 == 0:
			number_of_fives += 1
			number //= 5
		if number != 1:
			return -1
		else:
			return number_of_twos + number_of_threes * 2 + number_of_fives * 3

def Processing():
	global number_of_queries, number_n, minmum_number_of_moves
	for index in range(number_of_queries):
		print(Minimum_number_of_moves(number_n[index]))

def Output():
	global number_of_queries, number_n, minmum_number_of_moves
Input()
Processing()
Output()


q = int(input().strip())
while q:
	q -= 1
	n = int(input().strip())
	cnt = 0
	while n != 1:
		cnt += 1
		if n % 2 == 0:
			n = n // 2
		elif n % 3 == 0:
			n = n * 2 // 3
		elif n % 5 == 0:
			n = n * 4 // 5
		else:
			cnt = -1
			break
	print(cnt)


amount = int(input())
for i in range(amount):
	query = int(input())
	moves = 0
	while query > 1:
		if query % 2 == 0:
			query //= 2
		elif query % 3 == 0:
			query = query * 2 // 3
		elif query % 5 == 0:
			query = query * 4 // 5
		else:
			moves = -1
			break
		moves += 1
	print(moves)


q = int(input())
for _ in range(q):
	n = int(input())
	if n == 1:
		print('0')
	elif n % 2 != 0 and n % 3 != 0 and (n % 5 != 0):
		print('-1')
	else:
		cnt = 0
		while n != 1:
			if n % 2 == 0:
				n = n // 2
				cnt += 1
				continue
			if n % 3 == 0:
				n = 2 * n // 3
				cnt += 1
				continue
			if n % 5 == 0:
				n = 4 * n // 5
				cnt += 1
				continue
			break
		if n == 1:
			print(cnt)
		else:
			print('-1')


getInput = int(input())
for i in range(getInput):
	a = 0
	n = int(input())
	if n == 1:
		print(0)
		continue
	counts = 0
	while n != 1:
		if n % 2 == 0:
			n = int(n // 2)
			counts += 1
			continue
		if n % 3 == 0:
			n = int(2 * n // 3)
			counts += 1
			continue
		if n % 5 == 0:
			n = int(4 * n // 5)
			counts += 1
			continue
		a = 1
		n = 1
	if a == 1:
		print(-1)
	else:
		print(counts)


T = int(input())
for i in range(T):
	N = int(input())
	ans = 0
	while N % 5 == 0:
		N = N // 5
		ans += 3
	while N % 2 == 0:
		N = N // 2
		ans += 1
	while N % 3 == 0:
		N = N // 3
		ans += 2
	if N != 1:
		print(-1)
	else:
		print(ans)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
sys.setrecursionlimit(100000000)
inp = lambda : int(input())
strng = lambda : input().strip()
strl = lambda : list(input().strip())
jn = lambda x, l: x.join(map(str, l))
mul = lambda : map(int, input().strip().split())
mulf = lambda : map(float, input().strip().split())
seq = lambda : list(map(int, input().strip().split()))
mod = 1000000007

def ceil(x):
	d = int(x)
	if x == d:
		return int(x)
	return int(x) + 1

def ceildiv(x, d):
	if x % d == 0:
		return x // d
	return x // d + 1
t = int(input())
for _ in range(t):
	n = int(input())
	a5 = lambda x: 4 * x // 5
	a3 = lambda x: 2 * x // 3
	a2 = lambda x: x // 2
	ct = 0
	while n != 1:
		if n % 5 == 0:
			n = a5(n)
		elif n % 3 == 0:
			n = a3(n)
		elif n % 2 == 0:
			n = a2(n)
		else:
			ct = -1
			break
		ct += 1
	print(ct)


q = int(input())
for _ in range(q):
	n = int(input())
	l = 0
	m = 0
	while n != 1:
		if n % 2 == 0:
			n = n // 2
			l += 1
		elif n % 3 == 0:
			n = 2 * n // 3
			l += 1
		elif n % 5 == 0:
			n = 4 * n // 5
			l += 1
		elif n != 1:
			print(-1)
			m += 1
			break
	if m != 1:
		print(l)


def deli(n):
	result = 0
	while n % 2 == 0:
		n //= 2
		result += 1
	while n % 3 == 0:
		n //= 3
		result += 2
	while n % 5 == 0:
		n //= 5
		result += 3
	if n == 1:
		return result
	return -1
m = int(input())
a = list()
for i in range(m):
	number = int(input())
	a.append(deli(number))
for elem in a:
	print(elem)


for io in range(int(input())):
	n = int(input())
	a = 0
	while n % 2 == 0:
		a += 1
		n = n // 2
	while n % 3 == 0:
		a += 2
		n = n // 3
	while n % 5 == 0:
		a += 3
		n = n // 5
	if n == 1:
		print(a)
	else:
		print('-1')


t = int(input())
for i in range(t):
	n = int(input())
	w = 0
	c = 1
	while True:
		if n == 1:
			break
		if n % 2 == 0:
			n = n // 2
			w += 1
		elif n % 3 == 0:
			n = 2 * n // 3
			w += 1
		elif n % 5 == 0:
			n = 4 * n // 5
			w += 1
		else:
			print(-1)
			c = 0
			break
	if c == 1:
		print(w)


q = int(input())
for _ in range(q):
	n = int(input())
	if n == 1:
		print(0)
	else:
		c2 = 0
		c3 = 0
		c5 = 0
		while n % 5 == 0:
			c5 += 1
			n //= 5
			c2 += 2
		while n % 3 == 0:
			c3 += 1
			n //= 3
			c2 += 1
		while n % 2 == 0:
			c2 += 1
			n //= 2
		if n != 1:
			res = -1
		else:
			res = c2 + c3 + c5
		print(res)


import math
import sys
n = int(input())
for i in range(n):
	t = int(input())
	c = 0
	f = True
	while t != 1:
		while t % 2 == 0:
			c += 1
			t = t // 2
		if t % 3 == 0:
			c += 2
			t = t // 3
		elif t % 5 == 0:
			c += 3
			t = t // 5
		elif t != 1:
			print(-1)
			f = False
			break
	if f:
		print(c)


n = int(input())
count = 0
while n:
	q = int(input())
	while q:
		if q % 2 == 0:
			q = q // 2
			count += 1
		elif q % 3 == 0:
			q = 2 * q // 3
			count += 1
		elif q % 5 == 0:
			q = 4 * q // 5
			count += 1
		else:
			if q == 1:
				print(count)
			else:
				print(-1)
			break
	count = 0
	n = n - 1


n = int(input())
for i in range(n):
	count = 0
	status = True
	z = int(input())
	while status and z > 1:
		if z % 2 == 0:
			count += 1
			z = z // 2
		elif z % 3 == 0:
			count += 1
			z = 2 * z // 3
		elif z % 5 == 0:
			count += 1
			z = 4 * z // 5
		else:
			count = -1
			status = False
	print(count)


def calc(n):
	re = 0
	while n % 5 == 0:
		n = n // 5 * 4
		re += 1
	while n % 3 == 0:
		n = n // 3 * 2
		re += 1
	while n % 2 == 0:
		n = n // 2
		re += 1
	if n == 1:
		return re
	else:
		return -1
Q = int(input())
for _ in range(Q):
	print(calc(int(input())))


try:
	t = int(input())
	for __ in range(t):
		n = int(input())
		c = 0
		while n % 2 == 0:
			if n == 1:
				break
			n = n // 2
			c += 1
		while n % 3 == 0:
			if n == 1:
				break
			n = n // 3
			c += 2
		while n % 5 == 0:
			if n == 1:
				break
			n = n // 5
			c += 3
		if n == 1:
			print(c)
		else:
			print(-1)
except:
	pass


from sys import stdin
n = int(stdin.readline())
for i in range(n):
	x = int(stdin.readline())
	p2 = 0
	p3 = 0
	p5 = 0
	while x % 2 == 0:
		p2 += 1
		x = x // 2
	while x % 3 == 0:
		p3 += 1
		x = x // 3
	while x % 5 == 0:
		p5 += 1
		x = x // 5
	if not x == 1:
		print(-1)
	else:
		print(p5 + p3 + (p2 + p3 + 2 * p5))


for i in range(int(input())):
	n = int(input())
	ch2 = 0
	ch3 = 0
	ch5 = 0
	while n % 5 == 0:
		ch5 += 1
		n //= 5
		n *= 4
	while n % 3 == 0:
		ch3 += 1
		n //= 3
		n *= 2
	while n % 2 == 0:
		ch2 += 1
		n //= 2
	if n != 1:
		print(-1)
	else:
		print(ch2 + ch3 + ch5)


n = int(input())
for i in range(n):
	x = int(input())
	v2 = 0
	v3 = 0
	v5 = 0
	while x % 2 == 0:
		x = x // 2
		v2 += 1
	while x % 3 == 0:
		x = x // 3
		v3 += 1
	while x % 5 == 0:
		x = x // 5
		v5 += 1
	if x != 1:
		print(-1)
	else:
		print(v2 + 2 * v3 + 3 * v5)


def answer(n):
	count = 0
	while True:
		n1 = n
		if n % 2 == 0:
			n = n // 2
			count += 1
		if n % 3 == 0:
			n = 2 * n // 3
			count += 1
		if n % 5 == 0:
			n = 4 * n // 5
			count += 1
		if n1 == n:
			if n == 1:
				out = count
			else:
				out = -1
			break
	return out
q = int(input())
for i in range(q):
	in_ = int(input())
	out = answer(in_)
	print(out)


q = int(input())
for i in range(q):
	n = int(input())
	(cnt2, cnt3, cnt5) = (0, 0, 0)
	while n % 2 == 0:
		n //= 2
		cnt2 += 1
	while n % 3 == 0:
		n //= 3
		cnt3 += 1
	while n % 5 == 0:
		n //= 5
		cnt5 += 1
	if n != 1:
		print(-1)
	else:
		print(cnt2 + 2 * cnt3 + 3 * cnt5)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
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
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 types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

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 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 solve():
	n = int(inp())
	t = n
	c = 0
	while t > 1:
		if t % 2 == 0:
			t = t // 2
		elif t % 3 == 0:
			t = 2 * t // 3
		elif t % 5 == 0:
			t = 4 * t // 5
		else:
			c = -1
			break
		c += 1
	print(c)
testcase(int(inp()))


t = int(input())
for i in range(t):
	n = int(input())
	ans = 0
	while n % 5 == 0:
		ans += 3
		n //= 5
	while n % 3 == 0:
		ans += 2
		n //= 3
	while n % 2 == 0:
		ans += 1
		n //= 2
	print(ans if n == 1 else -1)


t = int(input())
for _ in range(t):
	n = int(input())
	t = 0
	f = 0
	th = 0
	while n % 3 == 0:
		n = 2 * n // 3
		th += 1
	while n % 5 == 0:
		n = 4 * n // 5
		f += 1
	while n % 2 == 0:
		n = n // 2
		t += 1
	if n != 1:
		print(-1)
	else:
		print(t + f + th)


import sys
import collections

def solve(x):
	d = collections.defaultdict(int)
	for divisor in [2, 3, 5]:
		while x % divisor == 0:
			d[divisor] += 1
			x //= divisor
	if x > 1:
		return -1
	return d[2] + 2 * d[3] + 3 * d[5]
_tc = int(input())
for _ in range(_tc):
	x = int(input())
	res = solve(x)
	print(res)


q = int(input())
for _ in range(q):
	n = int(input())
	res = 0
	while n % 5 == 0:
		n = 4 * n // 5
		res += 1
	while n % 3 == 0:
		n = 2 * n // 3
		res += 1
	while n % 2 == 0:
		n = n // 2
		res += 1
	if n > 1:
		print(-1)
	else:
		print(res)


n = int(input())
for i in range(n):
	x = 0
	a = int(input())
	while a > 1:
		if a % 2 == 0:
			a = a // 2
			x += 1
		elif a % 3 == 0:
			a = 2 * (a // 3)
			x += 1
		elif a % 5 == 0:
			a = 4 * (a // 5)
			x += 1
		else:
			x = -1
			break
	print(x)


t = int(input())

def devideIt(n):
	count = 0
	while n != 1:
		if n % 2 == 0:
			n = n // 2
		elif n % 3 == 0:
			n = 2 * n // 3
		elif n % 5 == 0:
			n = 4 * n // 5
		else:
			return -1
		count += 1
	return count
for i in range(t):
	print(devideIt(int(input())))


import sys
import math
import bisect

def main():
	for _ in range(int(input())):
		n = int(input())
		ans = 0
		while n % 5 == 0:
			n //= 5
			n *= 4
			ans += 1
		while n % 3 == 0:
			n //= 3
			n *= 2
			ans += 1
		while n % 2 == 0:
			n //= 2
			ans += 1
		if n == 1:
			print(ans)
		else:
			print(-1)
main()


q = 0
n = []

def Input():
	global n, q
	q = int(input())
	for index in range(q):
		x = int(input())
		n.append(x)

def Output():
	global n, q
	for index in range(q):
		a = 0
		b = 0
		c = 0
		while n[index] > 1:
			while n[index] % 2 == 0:
				a += 1
				n[index] = n[index] // 2
			while n[index] % 3 == 0:
				b += 1
				n[index] = n[index] // 3
			while n[index] % 5 == 0:
				c += 1
				n[index] = n[index] // 5
			break
		if n[index] == 1:
			print(a + 2 * b + 3 * c)
		else:
			print('-1')
Input()
Output()


n = int(input())

def check(n):
	p = 0
	while n:
		if n == 1:
			return p
		if n % 2 == 0:
			n //= 2
			p += 1
		elif n % 3 == 0:
			n = n // 3
			p += 2
		elif n % 5 == 0:
			n = n // 5
			p += 3
		else:
			return -1
while n:
	print(check(int(input())))
	n -= 1


n = int(input())
l = []
for i in range(n):
	l.append(int(input()))
for i in l:
	ans = i
	fail = 0
	c = 0
	while ans > 1:
		c += 1
		if ans % 2 == 0:
			ans = ans // 2
		elif ans % 3 == 0:
			ans = ans // 3 * 2
		elif ans % 5 == 0:
			ans = ans // 5 * 4
		else:
			fail = 1
			break
	if fail:
		print(-1)
	else:
		print(c)


for i in range(int(input())):
	n = int(input())
	(_2, _3, _5) = (0, 0, 0)
	while n % 2 == 0:
		_2 += 1
		n //= 2
	while n % 3 == 0:
		_3 += 1
		n //= 3
	while n % 5 == 0:
		_5 += 1
		n //= 5
	if n != 1:
		print('-1')
	else:
		print(_2 + _3 + 2 * _5 + _3 + _5)


n = int(input())
l = []
for i in range(n):
	a = int(input())
	l.append(a)
for i in range(n):
	count = 0
	x = l[i]
	while x != 1:
		s = x % 2
		z = x % 10
		k = x % 3
		if s == 0:
			count += 1
			x = x // 2
		elif z == 5:
			count += 1
			x = 4 * x // 5
		elif k == 0:
			x = x * 2 // 3
			count = count + 1
		else:
			count = -1
			break
	print(count)


q = int(input())
for _ in range(q):
	n = int(input())
	count = 0
	while n != 1:
		if n % 5 == 0:
			n //= 5
			count += 3
		elif n % 3 == 0:
			n //= 3
			count += 2
		elif n % 2 == 0:
			n //= 2
			count += 1
		else:
			print(-1)
			break
	else:
		print(count)


import sys
sys.setrecursionlimit(1000000)

class Main:

	def __init__(self):
		self.buff = None
		self.index = 0

	def next(self):
		if self.buff is None or self.index == len(self.buff):
			self.buff = self.next_line()
			self.index = 0
		val = self.buff[self.index]
		self.index += 1
		return val

	def next_line(self):
		return sys.stdin.readline().split()

	def next_ints(self):
		return [int(x) for x in sys.stdin.readline().split()]

	def next_int(self):
		return int(self.next())

	def solve(self):
		ca = self.next_int()
		for _ in range(ca):
			n = self.next_int()
			r = 0
			while n % 2 == 0:
				r += 1
				n //= 2
			while n % 3 == 0:
				r += 2
				n //= 3
			while n % 5 == 0:
				r += 3
				n //= 5
			print(r if n == 1 else -1)
Main().solve()


n = int(input())
results = []
for i in range(n):
	q = int(input())
	count = 0
	found = True
	while True:
		if q == 1:
			break
		elif q % 2 == 0:
			q = q // 2
			count += 1
		elif q % 3 == 0:
			q = 2 * q // 3
			count += 1
		elif q % 5 == 0:
			q = q * 4 // 5
			count += 1
		else:
			found = False
			break
	if found:
		results.append(count)
	else:
		results.append(-1)
print(*results, sep='\n')


n = int(input())
l = []
for i in range(n):
	l.append(int(input()))
for i in range(n):
	k = l.pop(0)
	c = 0
	while True:
		if k == 1:
			print(c)
			break
		elif k % 2 == 0:
			k = k // 2
			c += 1
		elif k % 3 == 0:
			k = 2 * k // 3
			c += 1
		elif k % 5 == 0:
			k = 4 * k // 5
			c += 1
		else:
			print(-1)
			break


q = int(input())
for i in range(q):
	n = int(input())
	arg = n % 5
	quantity_5 = 0
	while arg == 0:
		n //= 5
		quantity_5 += 1
		arg = n % 5
	arg = n % 3
	quantity_3 = 0
	while arg == 0:
		n //= 3
		quantity_3 += 1
		arg = n % 3
	arg = n % 2
	quantity_2 = 0
	while arg == 0:
		n //= 2
		quantity_2 += 1
		arg = n % 2
	if n != 1:
		print(-1)
	else:
		step = 3 * quantity_5 + 2 * quantity_3 + quantity_2
		print(step)


queries = int(input())
times = 0
while times < queries:
	n = int(input())
	count = 0
	while n != int(1):
		if n % 2 == 0:
			n = n // 2
		elif n % 3 == 0:
			n = 2 * n // 3
		elif n % 5 == 0:
			n = 4 * n // 5
		else:
			break
		count += 1
	if n == 1:
		print(count)
	else:
		print(-1)
	times += 1


from collections import deque
Q = int(input())
N = [int(input()) for _ in range(Q)]
for i in range(Q):
	n = N[i]
	cnt = 0
	flag = True
	while n != 1:
		if n % 2 == 0:
			n = n // 2
			cnt += 1
		elif n % 3 == 0:
			n = n // 3
			cnt += 2
		elif n % 5 == 0:
			n = n // 5
			cnt += 3
		else:
			flag = False
			break
	print(cnt if flag else -1)


from math import *
for _ in range(int(input())):
	n = int(input())
	i = 0
	while n % 5 == 0:
		n -= n // 5
		i += 1
	while n % 3 == 0:
		n -= n // 3
		i += 1
	while n % 2 == 0:
		n //= 2
		i += 1
	if n == 1:
		print(i)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	steps = 0
	while n > 1:
		if not n % 2:
			n //= 2
		elif not n % 3:
			n //= 3
			n *= 2
		elif not n % 5:
			n //= 5
			n *= 4
		else:
			break
		steps += 1
	print(steps if n == 1 else -1)


q = int(input())
for i in range(q):
	a = int(input())
	i = 0
	if a > 1:
		while a % 5 == 0:
			a //= 5
			a *= 4
			i += 1
		while a % 3 == 0:
			a //= 3
			a *= 2
			i += 1
		while a % 2 == 0:
			a //= 2
			i += 1
		if i == 0 or a != 1:
			i = -1
	print(i)


q = int(input())

def factorize(n, ans):
	if n == 1:
		return ans
	if n % 3 == 0:
		ans[1] += 1
		return factorize(n // 3, ans)
	if n % 5 == 0:
		ans[2] += 1
		return factorize(n // 5, ans)
	if n % 2 == 0:
		ans[0] += 1
		return factorize(n // 2, ans)
	return -1
while q:
	n = int(input())
	ans = [0] * 3
	m = factorize(n, ans)
	if m == -1:
		print(-1)
	else:
		ans[0] += 2 * ans[2] + ans[1]
		print(sum(ans))
	q -= 1


for _ in range(int(input())):
	n = int(input())
	res = True
	c = 0
	while n > 1:
		if n % 2 == 0:
			n //= 2
		elif n % 3 == 0:
			n //= 3
			n *= 2
		elif n % 5 == 0:
			n //= 5
			n *= 4
		else:
			res = False
			break
		c += 1
	print(c if res else -1)


for _ in range(int(input())):
	n = int(input())
	ans = 0
	while n % 2 == 0:
		ans += 1
		n //= 2
	while n % 3 == 0:
		ans += 2
		n //= 3
	while n % 5 == 0:
		ans += 3
		n //= 5
	if n == 1:
		print(ans)
	else:
		print(-1)


def powo(a, b):
	i = 0
	while a % b == 0:
		i = i + 1
		a = a // b
	return i
b = int(input())
for i in range(b):
	c = int(input())
	x1 = powo(c, 2)
	c = c // 2 ** x1
	x2 = powo(c, 3)
	c = c // 3 ** x2
	x3 = powo(c, 5)
	c = c // 5 ** x3
	if c != 1:
		print(-1)
	else:
		print(x1 + 2 * x2 + 3 * x3)


q = int(input())

def solve(n):
	acc = 0
	while n % 5 == 0:
		n //= 5
		acc += 3
	while n % 3 == 0:
		n //= 3
		acc += 2
	while n % 2 == 0:
		n //= 2
		acc += 1
	if n == 1:
		return acc
	return -1
for _ in range(q):
	n = int(input())
	print(solve(n))


q = int(input())
for i in range(q):
	op = 0
	a = int(input())
	while a % 5 == 0:
		op += 3
		a = a // 5
	while a % 3 == 0:
		op += 2
		a = a // 3
	while a % 2 == 0:
		op += 1
		a = a // 2
	if a != 1:
		print(-1)
	else:
		print(op)


q = int(input())
for i in range(q):
	n = int(input())
	count = 0
	while n != 0:
		if n % 2 == 0:
			n //= 2
			count += 1
			continue
		elif n % 3 == 0:
			n = n // 3 * 2
			count += 1
			continue
		elif n % 5 == 0:
			n = n // 5 * 4
			count += 1
			continue
		if n == 1:
			print(count)
		else:
			print(-1)
		break


def find_min(q):
	n = 0
	while q > 1:
		if q % 2 == 0:
			q -= q // 2
		elif q % 3 == 0:
			q -= q // 3
		elif q % 5 == 0:
			q -= q // 5
		else:
			return -1
		n += 1
	if q != 1:
		return -1
	return n
n = int(input())
for i in range(n):
	v = int(input())
	print(find_min(v))


from collections import deque
q = int(input())

def bfs(n):
	Q = deque()
	Q.append((n, 0))
	while Q:
		(n, m) = Q.popleft()
		if n <= 0:
			continue
		if n == 1:
			return print(m)
		for d in [2, 3, 5]:
			if n % d == 0:
				Q.append(((d - 1) * n // d, m + 1))
				break
	return print(-1)
for _ in range(q):
	n = int(input())
	bfs(n)


def solution():
	n = int(input())
	d = {2: 0, 3: 0, 5: 0}
	while n % 2 == 0:
		d[2] += 1
		n //= 2
	while n % 3 == 0:
		d[3] += 1
		n //= 3
	while n % 5 == 0:
		d[5] += 1
		n //= 5
	if n > 1:
		print(-1)
		return
	else:
		ans = d[2] + 2 * d[3] + 3 * d[5]
		print(ans)
		return

def main():
	test = int(input())
	for i in range(test):
		solution()
	return
main()


q = int(input())
for i in range(q):
	n = int(input())
	(num5, num3, num2) = (0, 0, 0)
	x = n
	while x % 5 == 0:
		x //= 5
		num5 += 1
	while x % 3 == 0:
		x //= 3
		num3 += 1
	while x % 2 == 0:
		x //= 2
		num2 += 1
	if x != 1:
		print(-1)
	else:
		print(3 * num5 + 2 * num3 + num2)


q = int(input())
for i in range(q):
	flag = 0
	two = 0
	three = 0
	five = 0
	res = 0
	n = int(input())
	while n > 1:
		if n % 2 == 0:
			two += 1
			n = n // 2
		elif n % 3 == 0:
			three += 1
			n = n // 3
		elif n % 5 == 0:
			five += 1
			n = n // 5
		else:
			flag = 1
			n = 1
	if flag == 1:
		print(-1)
	else:
		res = 2 * three + 3 * five + two
		print(res)


def solve(num):
	if num == 1:
		return 0
	cnt = 0
	while num > 1:
		if num % 2 == 0:
			num //= 2
			cnt += 1
		elif num % 3 == 0:
			num //= 3
			cnt += 2
		elif num % 5 == 0:
			num //= 5
			cnt += 3
		else:
			return -1
	return cnt
I = lambda : int(input())
n = I()
for i in range(n):
	num = I()
	print(solve(num))


t = int(input())
arr = []
while t > 0:
	t -= 1
	n = int(input())
	steps = 0
	flag = True
	while n != 1:
		flag = False
		if n % 2 == 0:
			n = n // 2
			steps += 1
			flag = True
		elif n % 3 == 0:
			n = 2 * n // 3
			steps += 1
			flag = True
		elif n % 5 == 0:
			n = 4 * n // 5
			steps += 1
			flag = True
		if not flag:
			break
	if flag:
		arr.append(steps)
	else:
		arr.append(-1)
for i in arr:
	print(i)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7

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

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

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

def S():
	return input()

def main():
	n = I()
	l = []
	for i in range(n):
		a = I()
		c = 0
		while True:
			if a == 1:
				l.append(c)
				break
			else:
				if a % 2 == 0:
					a //= 2
				elif a % 3 == 0:
					a //= 3
					a *= 2
				elif a % 5 == 0:
					a //= 5
					a *= 4
				else:
					l.append(-1)
					break
				c += 1
	for x in l:
		print(x)
main()


import sys
from math import ceil
from collections import deque
for _ in range(int(input())):
	n = int(input())
	ans = 0
	while n % 2 == 0:
		ans += 1
		n //= 2
	while n % 3 == 0:
		ans += 2
		n //= 3
	while n % 5 == 0:
		ans += 3
		n //= 5
	if n > 1:
		print(-1)
	else:
		print(ans)


n = int(input())
last = 2 ** 32 - 1
for _ in range(n):
	l = int(input().strip())
	ans = 0
	while l > 1:
		if l % 2 == 0:
			ans += 1
			l = l // 2
		elif l % 3 == 0:
			ans += 1
			l = 2 * l // 3
		elif l % 5 == 0:
			ans += 1
			l = 4 * l // 5
		else:
			break
	if l == 1:
		print(ans)
	else:
		print(-1)


import math
q = int(input())
for i in range(q):
	n = int(input())
	k = 0
	while n % 2 == 0 or n % 3 == 0 or n % 5 == 0:
		if n % 5 == 0:
			n = 4 * (n // 5)
			k = k + 1
		elif n % 3 == 0:
			n = 2 * (n // 3)
			k = k + 1
		else:
			n = n // 2
			k = k + 1
	if n == 1:
		print(k)
	else:
		print(-1)


n = int(input())
for i in range(n):
	query = int(input())
	moves = 0
	printou = 0
	while query > 1:
		if not query % 2:
			query = query // 2
			moves += 1
		elif not query % 3:
			query = 2 * query // 3
			moves += 1
		elif not query % 5:
			query = 4 * query // 5
			moves += 1
		else:
			print('-1')
			printou = 1
			break
	if not printou:
		print(moves)


q = int(input())
i = 0
while i < q:
	n = int(input())
	count = 0
	while n % 5 == 0:
		n //= 5
		count += 3
	while n % 3 == 0:
		n //= 3
		count += 2
	while n % 2 == 0:
		n //= 2
		count += 1
	print(-1 if n != 1 else count)
	i += 1


for _ in range(int(input())):
	n = int(input())
	dem = 0
	while n % 5 == 0 or n % 3 == 0:
		if n % 3 == 0:
			dem += 1
			n = n // 3 * 2
		if n % 5 == 0:
			dem += 1
			n = n // 5 * 4
	while n % 2 == 0:
		dem += 1
		n = n // 2
	if n == 1:
		print(dem)
	else:
		print(-1)


def divisor(num, div):
	ans = 0
	while num % div == 0:
		ans += 1
		num //= div
	return (ans, num)

def main():
	q = int(input())
	for _ in range(q):
		num = int(input())
		(ans, num) = divisor(num, 5)
		ans += 2 * ans
		(three, num) = divisor(num, 3)
		ans += three * 2
		(two, num) = divisor(num, 2)
		ans += two
		if num != 1:
			print(-1)
		else:
			print(ans)
main()


n = int(input())
l = list()
for i in range(n):
	temp = int(input())
	c = 0
	while temp != 1:
		if temp % 2 == 0:
			temp = temp // 2
		elif temp % 3 == 0:
			temp = 2 * temp // 3
		elif temp % 5 == 0:
			temp = 4 * temp // 5
		else:
			c = -1
			break
		c += 1
	l.append(c)
for i in l:
	print(i)


q = int(input())
for i in range(q):
	n = int(input())
	k = 0
	while True:
		if n == 1:
			print(k)
			break
		elif n % 2 == 0:
			n //= 2
		elif n % 3 == 0:
			n //= 3
			n *= 2
		elif n % 5 == 0:
			n //= 5
			n *= 4
		else:
			print(-1)
			break
		k += 1


from decimal import *
n = int(input())
count = 0
l = []
for i in range(n):
	a = int(input())
	l.append(a)
for m in l:
	m = Decimal(m)
	while m > 1:
		if m % 2 == 0:
			m = m / 2
			count += 1
		elif m % 3 == 0:
			m = 2 * m / 3
			count += 1
		elif m % 5 == 0:
			m = 4 * m / 5
			count += 1
		else:
			count = -1
			break
		if m < 1:
			count = -1
			break
	print(count)
	count = 0


q = int(input())
for I in range(q):
	n = int(input())
	ans = 0
	poss = 1
	while n != 1:
		if n % 2 and n % 3 and n % 5:
			poss = 0
			break
		if n % 2 == 0:
			n //= 2
		elif n % 3 == 0:
			n = 2 * n // 3
		elif n % 5 == 0:
			n = 4 * n // 5
		ans += 1
	if poss:
		print(ans)
	else:
		print(-1)


q = int(input())
for i in range(q):
	n = int(input())
	c = 0
	while n >= 1:
		if n % 2 == 0:
			n -= n // 2
		elif n % 3 == 0:
			n -= n // 3
		elif n % 5 == 0:
			n -= n // 5
		else:
			break
		c += 1
	if n == 1:
		print(c, end='\n')
	else:
		print('-1', end='\n')


def oper(a):
	count = 0
	while a % 3 == 0:
		a = a // 3
		count += 2
	while a % 5 == 0:
		a = a // 5
		count += 3
	while a % 2 == 0:
		a = a // 2
		count += 1
	if a == 1:
		return count
	return -1
q = int(input())
for i in range(q):
	print(oper(int(input())))


def compute(n):
	nums = [2, 3, 5]
	fs = [0, 0, 0]
	for i in range(3):
		if n % nums[i] == 0:
			n = n // nums[i]
			fs[i] = 1
			while n % nums[i] == 0:
				n = n // nums[i]
				fs[i] = fs[i] + 1
		if n == 1:
			break
	if n != 1:
		return -1
	return fs[0] + 2 * fs[1] + 3 * fs[2]

def main():
	q = int(input())
	for i in range(q):
		num = int(input())
		print(compute(num))
main()


tc = int(input())
for _ in range(tc):
	a = int(input())
	ans = 0
	while a != 1:
		ans += 1
		if a % 2 == 0:
			a //= 2
		elif a % 3 == 0:
			a //= 3
			a *= 2
		elif a % 5 == 0:
			a //= 5
			a *= 4
		else:
			break
	if a != 1:
		print(-1)
	else:
		print(ans)


def divide(x):
	global c
	if x == 1:
		return c
	if x % 2 == 0:
		divide(x // 2)
	elif x % 3 == 0:
		divide(x * 2 // 3)
	elif x % 5 == 0:
		divide(x * 4 // 5)
	else:
		c = -1
		return c
	if c != -1:
		c += 1
	return c
for i in range(int(input())):
	(x, c) = (int(input()), 0)
	print(divide(x))


x = int(input())

def numberTimes(n):
	if n == 1:
		return 0
	if n % 2 == 0:
		m = numberTimes(int(n // 2))
		if m == -1:
			return -1
		return 1 + m
	if n % 3 == 0:
		m = numberTimes(int(n // 3))
		if m == -1:
			return -1
		return 2 + m
	if n % 5 == 0:
		m = numberTimes(int(n // 5))
		if m == -1:
			return -1
		return 3 + m
	return -1
for i in range(x):
	print(numberTimes(int(input())))


def main():
	q = int(input())
	for _ in range(q):
		n = int(input())
		n2 = 0
		while n % 2 == 0:
			n //= 2
			n2 += 1
		n3 = 0
		while n % 3 == 0:
			n //= 3
			n3 += 1
		n5 = 0
		while n % 5 == 0:
			n //= 5
			n5 += 1
		res = -1
		if n == 1:
			res = n2 + 2 * n3 + 3 * n5
		print(res)
main()


for i in range(int(input())):
	num = int(input())
	ans = 0
	while num % 2 == 0:
		num = num // 2
		ans += 1
	while num % 3 == 0:
		num = num // 3
		ans += 2
	while num % 5 == 0:
		num = num // 5
		ans += 3
	print(ans if num == 1 else -1)


from sys import stdin, stdout
import bisect
import math

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)
	l[0] = 0
	l[1] = 0
	prime = [2]
	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(3, limit + 1, 2):
		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 gcd(a, b):
	while b:
		a = a % b
		(b, a) = (a, b)
	return a

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

def solve():
	n = inp()
	c = 0
	while n % 5 == 0:
		n = 4 * n // 5
		c += 1
	while n % 3 == 0:
		n = 2 * n // 3
		c += 1
	while n % 2 == 0:
		n = n >> 1
		c += 1
	if n == 1:
		print(c)
	else:
		print(-1)
for _ in range(inp()):
	solve()


t = int(input())
d = {}
for i in range(t):
	x = int(input())
	ans = 0
	while x % 5 == 0:
		x = 4 * x // 5
		ans += 1
	while x % 3 == 0:
		x = 2 * x // 3
		ans += 1
	p = 0
	cur = 1
	while cur <= 1e+18:
		d[cur] = p
		cur *= 2
		p += 1
	if x in d:
		ans += d[x]
		print(ans)
	else:
		print(-1)


def number_of_moves(n):
	moves = 0
	if n == 1:
		return 0
	while n != 1:
		if n == 1:
			break
		elif n % 5 == 0:
			n = 4 * n // 5
			moves += 1
		elif n % 3 == 0:
			n = 2 * n // 3
			moves += 1
		elif n % 2 == 0:
			n = n // 2
			moves += 1
		else:
			break
	if n == 1:
		return moves
	else:
		return -1
t = int(input())
while t > 0:
	n = int(input())
	op = number_of_moves(n)
	print(op)
	t -= 1


from collections import deque
from math import log, sqrt, ceil

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

def si():
	return input()

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

def li():
	return list(mi())
t = ii()
while t:
	t -= 1
	n = ii()
	c = 0
	f = 0
	while 1:
		if n == 1:
			break
		if n % 2 == 0:
			n //= 2
		elif n % 3 == 0:
			n //= 3
			n *= 2
		elif n % 5 == 0:
			n //= 5
			n *= 4
		else:
			print('-1')
			f = 1
			break
		c += 1
	if f == 0:
		print(c)


for i in range(int(input())):
	(X, Count) = (int(input()), 0)
	while X != 1:
		if X % 2 == 0:
			X = X // 2
		elif X % 3 == 0:
			X = X * 2 // 3
		elif X % 5 == 0:
			X = X * 4 // 5
		else:
			Count = -1
			break
		Count += 1
	print(Count)


def sol():
	cnt = 0
	n = int(input())
	while n != 1:
		if not n % 2:
			n = n // 2
			cnt += 1
		elif not n % 3:
			n = n // 3 * 2
			cnt += 1
		elif not n % 5:
			n = n // 5 * 4
			cnt += 1
		else:
			return '-1'
	return cnt
t = int(input())
for i in range(t):
	print(sol())


n = int(input())
a = []
for i in range(n):
	m = int(input())
	c = 0
	d = 0
	e = 0
	ans = []
	while m % 2 == 0:
		e += 1
		m = m // 2
	while m % 5 == 0:
		c += 1
		m = m // 5
	while m % 3 == 0:
		d += 1
		m = m // 3
	if m == 1:
		ans = 3 * c + 2 * d + e
	else:
		ans = -1
	a.append(ans)
for i in a:
	print(i)


t = int(input())
for _ in range(t):
	n = int(input())
	moves = 0
	while True:
		if n == 1:
			print(moves)
			break
		if n % 2 == 0 or n % 3 == 0 or n % 5 == 0:
			while n % 2 == 0:
				n = n // 2
				moves += 1
			while n % 3 == 0:
				n = 2 * n // 3
				moves += 1
			while n % 5 == 0:
				n = 4 * n // 5
				moves += 1
		else:
			print(-1)
			break


def fun(n):
	count = 0
	while n % 5 == 0:
		n = 4 * n // 5
		count += 1
	while n % 3 == 0:
		n = 2 * n // 3
		count += 1
	while n % 2 == 0:
		n = n // 2
		count += 1
	if n == 1:
		return count
	else:
		return -1
for _ in range(int(input())):
	n = int(input())
	print(fun(n))


import sys
import math
from collections import defaultdict

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

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

def rln(n):
	l = [None] * n
	for i in range(n):
		l[i] = int(rl())
	return l

def primes(n, div):
	count = 0
	cur = n
	while cur % div == 0:
		cur = cur // div
		count += 1
	return count

def solve(num):
	expo2 = primes(num, 2)
	expo3 = primes(num, 3)
	expo5 = primes(num, 5)
	if 2 ** expo2 * 3 ** expo3 * 5 ** expo5 != num:
		print(-1)
	else:
		print(expo2 + 2 * expo3 + 3 * expo5)
test = int(input())
for _ in range(test):
	solve(int(input()))


x = int(input())
for i in range(0, x):
	k = 0
	y = int(input())
	while y > 1:
		if y % 5 == 0:
			y = 4 * y // 5
			k = k + 1
		if y % 3 == 0:
			y = 2 * y // 3
			k = k + 1
		if y % 2 == 0:
			y = y // 2
			k = k + 1
		if y % 5 != 0 and y % 3 != 0 and (y % 2 != 0) and (y != 1):
			print('-1')
			k = 0
			break
	if k != 0:
		print(k)
	if k == 0 and y == 1:
		print(k)


q = int(input())

def solve(n):
	i = 0
	while True:
		if n == 1:
			break
		if n % 2 == 0:
			i += 1
			n = n // 2
		elif n % 3 == 0:
			i += 1
			n = 2 * n // 3
		elif n % 5 == 0:
			i += 1
			n = 4 * n // 5
		else:
			return -1
	return i
for _ in range(q):
	n = int(input())
	print(solve(n))


def int_lst_input():
	return [int(val) for val in input().split(' ')]

def int_input():
	return int(input())

def print_lst(lst):
	print(' '.join([str(val) for val in lst]))

def solve():
	q = int_input()
	for i in range(q):
		n = int_input()
		seen = set()
		count = 0
		while n > 0 and n not in seen:
			seen.add(n)
			if n % 5 == 0:
				n = 4 * n // 5
			elif n % 3 == 0:
				n = 2 * n // 3
			elif n % 2 == 0:
				n = n // 2
			else:
				break
			count += 1
		if n == 1:
			print(count)
		else:
			print(-1)
solve()


from sys import stdin

def solve():
	q = int(stdin.readline().strip())
	for _ in range(q):
		n = int(stdin.readline().strip())
		cost = 0
		while n % 3 == 0:
			n //= 3
			cost += 2
		while n % 5 == 0:
			n //= 5
			cost += 3
		while n % 2 == 0:
			n //= 2
			cost += 1
		if n == 1:
			print(cost)
		else:
			print(-1)
solve()


def divide(n):
	iter = 0
	while n != 1:
		if n % 2 == 0:
			n //= 2
		elif n % 3 == 0:
			n = n * 2 // 3
		elif n % 5 == 0:
			n = n * 4 // 5
		else:
			return -1
		iter += 1
	return iter
q = int(input())
for _ in range(q):
	n = int(input())
	print(divide(n))


n = int(input())
a = []
for i in range(n):
	q = int(input())
	count = 0
	while q != 1:
		if q % 2 == 0:
			q = q // 2
			count += 1
		elif q % 3 == 0:
			q = q - q // 3
			count += 1
		elif q % 5 == 0:
			q = q - q // 5
			count += 1
		else:
			count = -1
			break
	a.append(count)
for i in range(n):
	print(a[i])


def div(x):
	c = 0
	while x % 2 == 0:
		x = x // 2
		c += 1
	while x % 3 == 0:
		x = x // 3
		c += 2
	while x % 5 == 0:
		x = x // 5
		c += 3
	if x != 1:
		return -1
	return c
q = int(input())
l = []
for i in range(q):
	l.append(int(input()))
for el in l:
	print(div(el))


t = int(input())
while t:
	n = int(input())
	steps = 0
	while n != 1:
		if n % 3 == 0:
			n = 2 * n // 3
			steps += 1
		elif n % 5 == 0:
			n = 4 * n // 5
			steps += 1
		elif n % 2 == 0:
			n = n // 2
			steps += 1
		else:
			steps = -1
			break
	print(steps)
	t -= 1


q = int(input())
for _ in range(q):
	n = int(input())
	(steps, c3, c5) = (0, 3, 5)
	while c3:
		if not n % c5:
			steps += c3
			n //= c5
		else:
			(c5, c3) = (c3, c3 - 1)
	if n != 1:
		steps = -1
	print(steps)


import math
import sys

def prime_factors(n):
	while n % 2 == 0:
		yield 2
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			yield i
			n = n / i
	if n > 2:
		yield n
q = int(next(sys.stdin))
for _ in range(q):
	x = int(next(sys.stdin))
	if x == 1:
		print(0)
	else:
		result = 0
		while x != 1:
			if x % 2 == 0:
				x //= 2
				result += 1
			elif x % 3 == 0:
				x //= 3
				result += 2
			elif x % 5 == 0:
				x //= 5
				result += 3
			else:
				result = -1
				break
		print(result)


test_case = int(input())
for _ in range(test_case):
	n = int(input())
	i = 0
	while n > 1:
		if n % 2 == 0:
			n = n // 2
		elif n % 3 == 0:
			n = 2 * n // 3
		elif n % 5 == 0:
			n = 4 * n // 5
		else:
			i = -1
			break
		i += 1
	print(i)


def solve(n):
	(p2, p3, p5) = (0, 0, 0)
	while n % 2 == 0:
		n //= 2
		p2 += 1
	while n % 3 == 0:
		n //= 3
		p3 += 1
	while n % 5 == 0:
		n //= 5
		p5 += 1
	if n != 1:
		return -1
	return 2 * p3 + 3 * p5 + p2
q = int(input())
for i in range(q):
	n = int(input())
	print(solve(n))


def f(n):
	n = int(n)
	mas = []
	while n % 2 == 0:
		mas += [2]
		n = n // 2
	while n % 3 == 0:
		mas += [3]
		n = n // 3
	while n % 5 == 0:
		mas += [5]
		n = n // 5
	if n != 1:
		print(-1)
	else:
		dva = mas.count(2) + mas.count(3) + 2 * mas.count(5)
		tri = mas.count(3)
		pyat = mas.count(5)
		print(dva + tri + pyat)
a = int(input())
sup = []
for i in range(a):
	sup += [input()]
for i in range(a):
	f(sup[i])


ansList = []
a = input()
for i in range(int(a)):
	b = int(input())
	ans = 0
	while b % 2 == 0:
		b = b // 2
		ans += 1
	while b % 3 == 0:
		b = b // 3
		ans += 2
	while b % 5 == 0:
		b = b // 5
		ans += 3
	if b == 1:
		ansList.append(ans)
	else:
		ansList.append(-1)
for j in ansList:
	print(j)


q = int(input())
for _ in range(q):
	n = int(input())
	cnt = 0
	bad = False
	while n != 1:
		cnt += 1
		if n % 2 == 0:
			n = n // 2
		elif n % 3 == 0:
			n = n // 3 * 2
		elif n % 5 == 0:
			n = n // 5 * 4
		else:
			bad = True
			break
	if bad:
		print(-1)
	else:
		print(cnt)


test = int(input())
for t in range(test):
	n = int(input())
	res = 0
	f = 0
	while n != 1:
		if n % 2 == 0:
			res += 1
			n = n // 2
		elif n % 3 == 0:
			res += 2
			n = n // 3
		elif n % 5 == 0:
			res += 3
			n = n // 5
		else:
			print(-1)
			f = 1
			break
	if f == 0:
		print(res)


a = int(input())
for i in range(a):
	b = int(input())
	ans = 0
	while True:
		c = 1
		if b % 2 == 0:
			c -= 1
			b //= 2
			ans += 1
		if b % 3 == 0:
			c -= 1
			b //= 3
			ans += 2
		if b % 5 == 0:
			c -= 1
			b //= 5
			ans += 3
		if c == 1:
			break
	if b != 1:
		ans = -1
	print(ans)


q = int(input())
for i in range(q):
	n = int(input())
	c = 0
	bad = False
	while n != 1:
		if n % 2 == 0:
			n = n // 2
			c += 1
		elif n % 3 == 0:
			n = 2 * (n // 3)
			c += 1
		elif n % 5 == 0:
			n = 4 * (n // 5)
			c += 1
		else:
			bad = True
			break
	if bad:
		print(-1)
	else:
		print(c)


def divideIt(n):
	cnt = 0
	while n >= 1:
		if n % 2 == 0:
			n = n // 2
			cnt += 1
		elif n % 3 == 0:
			n = 2 * (n // 3)
			cnt += 1
		elif n % 5 == 0:
			n = 4 * (n // 5)
			cnt += 1
		else:
			if n == 1:
				return cnt
			return -1
t = int(input())
for _ in range(t):
	n = int(input())
	print(divideIt(n))


def replacer(n, a):
	for i in range(n):
		steps = 0
		k = a[i]
		while True:
			if k % 2 == 0:
				k = k // 2
			elif k % 3 == 0:
				k = 2 * (k // 3)
			elif k % 5 == 0:
				k = 4 * (k // 5)
			elif k != 1:
				a[i] = -1
				break
			else:
				a[i] = steps
				break
			steps += 1
	for i in range(n):
		print(a[i])
n = int(input())
a = []
for i in range(n):
	k = int(input())
	a.append(k)
replacer(n, a)


from sys import setcheckinterval, stdin
setcheckinterval(1000)
iin = lambda : int(stdin.readline())
lin = lambda : list(map(int, stdin.readline().split()))
for _ in range(iin()):
	n = iin()
	ans = 0
	while n != 1:
		ans += 1
		if n % 2 == 0:
			n //= 2
		elif n % 3 == 0:
			n = 2 * (n // 3)
		elif n % 5 == 0:
			n = 4 * (n // 5)
		else:
			print(-1)
			break
	else:
		print(ans)


for _ in [0] * int(input()):
	(n, r) = (int(input()), 0)
	for k in zip([1, 2, 3], [2, 3, 5]):
		while n % k[1] == 0:
			n //= k[1]
			r += k[0]
	print([r, -1][n > 1])


N = int(input())

def calc(n, d):
	ret = 0
	while n % d == 0:
		ret += 1
		n //= d
	return (ret, n)
for _ in range(N):
	q = int(input())
	(ct2, q) = calc(q, 2)
	(ct3, q) = calc(q, 3)
	(ct5, q) = calc(q, 5)
	if q == 1:
		print(ct2 + ct3 * 2 + ct5 * 3)
	else:
		print(-1)


import sys
t = int(input())
for o in range(t):
	n = int(input())
	count = 0
	flag = 1
	x = y = z = -1
	while n > 1:
		if n % 5 == 0:
			x = 4 * (n // 5)
		if n % 3 == 0:
			y = 2 * (n // 3)
		if n % 2 == 0:
			z = n // 2
		if x == -1 and y == -1 and (z == -1):
			print('-1')
			flag = 0
			break
		count += 1
		if x != -1 and y != -1 and (z != -1):
			n = min(x, y, z)
		elif x != -1 and y != -1:
			n = min(x, y)
		elif z != -1 and y != -1:
			n = min(z, y)
		elif x != -1 and z != -1:
			n = min(x, z)
		elif x != -1:
			n = x
		elif y != -1:
			n = y
		else:
			n = z
		x = y = z = -1
	if flag == 1:
		print(count)


n = int(input())
for i in range(n):
	z = True
	q = int(input())
	s = 0
	while q != 1:
		if q % 2 == 0:
			q = q // 2
			s += 1
		elif q % 3 == 0:
			q = q * 2 // 3
			s += 1
		elif q % 5 == 0:
			q = q * 4 // 5
			s += 1
		else:
			z = False
			break
	if z:
		print(s)
	else:
		print(-1)


from sys import stdin
n = int(stdin.readline().strip())
for i in range(n):
	n1 = int(stdin.readline().strip())
	ans = 0
	while n1 != 1:
		if n1 % 2 == 0:
			n1 = n1 // 2
			ans += 1
		elif n1 % 3 == 0:
			n1 = 2 * n1 // 3
			ans += 1
		elif n1 % 5 == 0:
			n1 = 4 * n1 // 5
			ans += 1
		else:
			ans = -1
			break
	print(ans)


q = int(input())
while q:
	n = int(input())
	count = 0
	pre = n
	cond = True
	while n != 1:
		if n % 2 == 0:
			n = n // 2
			count += 1
		if n % 3 == 0:
			n = 2 * n // 3
			count += 1
		if n % 5 == 0:
			n = 4 * n // 5
			count += 1
		if n % 2 != 0 and n % 3 != 0 and (n % 5 != 0) and (n > 1):
			print(-1)
			cond = False
			break
	if cond:
		print(count)
	q -= 1


ans = 0
q = int(input())
while q > 0:
	ans = 0
	n = int(input())
	while n > 1:
		if n % 2 == 0 or n % 3 == 0 or n % 5 == 0:
			if n % 2 == 0:
				ans = ans + 1
				n = n // 2
			elif n % 3 == 0:
				ans = ans + 1
				n = 2 * n // 3
			elif n % 5 == 0:
				ans = ans + 1
				n = 4 * n // 5
		else:
			break
	if n == 1:
		print(ans)
	else:
		print(-1)
	q = q - 1


def fun(n, t):
	if n == 1:
		print(t)
		return
	elif n % 2 == 0:
		t += 1
		n = n // 2
		fun(n, t)
	elif n % 3 == 0:
		t += 1
		n = 2 * n // 3
		fun(n, t)
	elif n % 5 == 0:
		t += 1
		n = 4 * n // 5
		fun(n, t)
	else:
		print('-1')
		return
for i in range(int(input())):
	n = int(input())
	fun(n, t=0)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	count = 0
	count3 = 0
	count5 = 0
	flag = 0
	n = int(input())
	while n != 1:
		if n % 2 == 0:
			n = n // 2
			count += 1
		elif n % 3 == 0:
			n = n // 3
			count3 += 1
		elif n % 5 == 0:
			n = n // 5
			count5 += 1
		else:
			flag = 1
			break
	res = count + count3 * 2 + count5 * 3
	if flag == 0:
		print(res)
	else:
		print(-1)


n = int(input())

def r(num, tries=0):
	if num == 1:
		return tries
	elif num % 2 == 0:
		return r(num // 2, tries + 1)
	elif num % 3 == 0:
		return r(2 * num // 3, tries + 1)
	elif num % 5 == 0:
		return r(4 * num // 5, tries + 1)
	else:
		return -1
for i in range(n):
	number = int(input())
	val = r(number)
	print(val)


def dkwpwn(num):
	count = 0
	done = None
	while num != 1 and (not done):
		done = True
		if num % 2 == 0:
			num = num // 2
			count += 1
			done = False
		elif num % 3 == 0:
			num = num // 3 * 2
			count += 1
			done = False
		elif num % 5 == 0:
			num = num // 5 * 4
			count += 1
			done = False
	return -1 if done else count
T = int(input())
for _ in range(T):
	num = int(input())
	print(dkwpwn(num))


from sys import stdin
import math
from collections import defaultdict, deque
import bisect
I = stdin.readline
t = int(I())
for _ in range(t):
	n = int(I())
	ans = 0
	while n != 1:
		if n % 2 == 0:
			n //= 2
			ans += 1
		elif n % 3 == 0:
			n = 2 * (n // 3)
			ans += 1
		elif n % 5 == 0:
			n = 4 * (n // 5)
			ans += 1
		else:
			break
	if n == 1:
		print(ans)
	else:
		print(-1)


def main():
	q = int(input())
	for i in range(q):
		number = int(input())
		isDivisible = True
		moves = 0
		while isDivisible:
			if number % 2 == 0:
				number = number // 2
				moves = moves + 1
			elif number % 3 == 0:
				number = 2 * number // 3
				moves = moves + 1
			elif number % 5 == 0:
				number = 4 * number // 5
				moves = moves + 1
			else:
				isDivisible = False
		if number == 1:
			print(moves)
		else:
			print(-1)
main()


def scand():
	return int(input())

def scana():
	return [int(x) for x in input().split()]
n = scand()

def solve(x):
	ret = 0
	while x > 1:
		if not x % 5:
			ret += 3
			x //= 5
		elif not x % 3:
			ret += 2
			x //= 3
		elif not x % 2:
			ret += 1
			x //= 2
		else:
			return -1
	return ret
for i in range(n):
	m = scand()
	print(solve(m))


import math

def trial_division(n):
	c = 0
	while True:
		if n % 2 == 0:
			n //= 2
			c += 1
		else:
			break
	while True:
		if n % 3 == 0:
			n //= 3
			c += 2
		else:
			break
	while True:
		if n % 5 == 0:
			n //= 5
			c += 3
		else:
			break
	return (c, n)

def main():
	for q in range(int(input())):
		num = int(input())
		(c, n) = trial_division(num)
		if n == 1:
			print(c)
		else:
			print(-1)
main()


n = int(input())
for x in range(n):
	l = int(input())
	wyn = 0
	loop = True
	while l != 1:
		if l % 5 == 0:
			l = 4 * l // 5
			wyn += 1
			continue
		if l % 3 == 0:
			l = 2 * l // 3
			wyn += 1
			continue
		if l % 2 == 0:
			l = l // 2
			wyn += 1
			continue
		print('-1')
		loop = False
		break
	if loop == True:
		print(wyn)
	else:
		continue


from math import *
t = int(input())
for _ in range(t):
	n = int(input())
	if n == 1:
		print('0')
	else:
		c = 0
		f = 0
		while n > 1:
			if n % 5 == 0:
				c = c + 3
				n = n // 5
			elif n % 3 == 0:
				c = c + 2
				n = n // 3
			elif n % 2 == 0:
				c = c + 1
				n = n // 2
			else:
				f = 1
				break
		if f == 1:
			print('-1')
		else:
			print(c)


t = eval(input())
for g in range(t):
	n = eval(input())
	s = 0
	while n % 5 == 0:
		n //= 5
		s += 3
	while n % 3 == 0:
		n //= 3
		s += 2
	while n % 2 == 0:
		n //= 2
		s += 1
	if n == 1:
		print(s)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	ans = 0
	flag = False
	while n > 1:
		flag1 = False
		if n % 2 == 0:
			n //= 2
			ans += 1
			flag1 = True
		elif 2 * n % 3 == 0:
			n = 2 * n // 3
			ans += 1
			flag1 = True
		elif 4 * n % 5 == 0:
			n = 4 * n // 5
			ans += 1
			flag1 = True
		if not flag1:
			flag = True
			break
		if n < 0:
			flag = True
	if not flag:
		print(ans)
	else:
		print(-1)


q = int(input())
while q:
	q -= 1
	n = int(input())
	c = 0
	while n != 1:
		c += 1
		if not n % 5:
			n = 4 * n // 5
		elif not n % 3:
			n = 2 * n // 3
		elif not n % 2:
			n //= 2
		else:
			c = -1
			break
	if c:
		print(c)
	else:
		print(c)


for i in range(int(input())):
	n = int(input())
	cnt = 0
	while n % 2 == 0:
		n //= 2
		cnt += 1
	while n % 3 == 0:
		n //= 3
		cnt += 2
	while n % 5 == 0:
		n //= 5
		cnt += 3
	print([cnt, -1][n != 1])


q = int(input())
for j in range(q):
	i = int(input())
	s = 0
	if i > 1:
		while i != 1:
			k = s
			if i % 2 == 0:
				s += 1
				i //= 2
			elif i % 3 == 0:
				s += 1
				i = i * 2 // 3
			elif i % 5 == 0:
				s += 1
				i = i * 4 // 5
			if k == s:
				s = 0
				break
		print([-1, s][s > 0])
	else:
		print(0)


cases = int(input())
for _ in range(cases):
	n = int(input())
	(cnt2, cnt3, cnt5) = (0, 0, 0)
	if n == 1:
		print(0)
		continue
	while n % 2 == 0:
		cnt2 += 1
		n = n // 2
	while n % 3 == 0:
		cnt3 += 1
		n = n // 3
	while n % 5 == 0:
		cnt5 += 1
		n = n // 5
	if n != 1:
		print(-1)
	else:
		print(cnt2 + 2 * cnt3 + 3 * cnt5)


def get(i):
	ans = 0
	while i % 5 == 0:
		i = 4 * (i // 5)
		ans += 1
	while i % 3 == 0:
		i = 2 * (i // 3)
		ans += 1
	while i % 2 == 0:
		i //= 2
		ans += 1
	return ans if i == 1 else -1
q = int(input())
for _ in range(q):
	print(get(int(input())))


n = int(input())
for i in range(n):
	n = int(input())
	count = 0
	while True:
		if n % 2 == 0:
			n //= 2
			count += 1
		elif n % 3 == 0:
			n //= 3
			count += 2
		elif n % 5 == 0:
			n //= 5
			count += 3
		elif n == 1:
			print(count)
			break
		else:
			print(-1)
			break


for q in range(int(input())):
	n = int(input())
	flag = 0
	count = 0
	while n % 2 == 0 or n % 3 == 0 or n % 5 == 0:
		if n % 2 == 0:
			n //= 2
			count += 1
		elif n % 3 == 0:
			n //= 3
			n *= 2
			count += 1
		else:
			n //= 5
			n *= 4
			count += 1
		if n == 1:
			flag = 1
			break
	if flag == 0 and n != 1:
		print(-1)
	else:
		print(count)


from sys import stdin, stdout, exit
q = int(input())
for it in range(q):
	n = int(stdin.readline())
	ans = 0
	while n % 5 == 0:
		n //= 5
		n *= 4
		ans += 1
	while n % 3 == 0:
		n //= 3
		n *= 2
		ans += 1
	while n % 2 == 0:
		n //= 2
		ans += 1
	if n == 1:
		stdout.write(str(ans) + '\n')
	else:
		stdout.write('-1\n')


t = int(input())
for i in range(t):
	x = int(input())
	temp = 0
	while x != 1:
		if x % 2 == 0:
			x = x // 2
			temp += 1
		elif x % 3 == 0:
			x = 2 * x // 3
			temp += 1
		elif x % 5 == 0:
			x = x * 4 // 5
			temp += 1
		else:
			temp = -1
			break
	print(temp)


a = int(input())
c = []
for i in range(a):
	b = int(input())
	k = 0
	while b != 1:
		if b % 2 == 0:
			b = b // 2
			k += 1
		elif b % 3 == 0:
			b = 2 * b // 3
			k += 1
		elif b % 5 == 0:
			b = 4 * b // 5
			k += 1
		else:
			k = -1
			break
	c.append(k)
for i in range(a):
	print(c[i])


(x, r) = (int(input()), '')
for i in range(x):
	n = int(input())
	c = 0
	while n % 2 == 0:
		n = n // 2
		c += 1
	while n % 3 == 0:
		n = n // 3
		c += 2
	while n % 5 == 0:
		n = n // 5
		c += 3
	if n != 1:
		r += '-1' + '\n'
	else:
		r += str(c) + '\n'
print(r)


T = int(input())
for _ in range(T):
	N = int(input())
	cnt = 0
	while N != 1:
		if N % 2 == 0:
			N = N // 2
		elif N % 3 == 0:
			N = 2 * (N // 3)
		elif N % 5 == 0:
			N = 4 * (N // 5)
		else:
			print(-1)
			break
		cnt += 1
	else:
		print(cnt)


q = int(input())
for kase in range(q):
	n = int(input())
	(c2, c3, c5) = (0, 0, 0)
	x = n
	while x > 1:
		if x % 2 == 0:
			x //= 2
			c2 += 1
		elif x % 3 == 0:
			x //= 3
			c3 += 1
		elif x % 5 == 0:
			x //= 5
			c5 += 1
		else:
			break
	if x > 1:
		print('-1')
		continue
	print(c2 + c3 * 2 + c5 * 3)


import os
import sys
from io import BytesIO, IOBase
import math
from decimal import Decimal
from decimal import *
from collections import defaultdict, deque
import heapq
from decimal import Decimal
getcontext().prec = 25
abcd = 'abcdefghijklmnopqrstuvwxyz'
MOD = 1000000007
BUFSIZE = 8192
from bisect import bisect_left, bisect_right

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())):
	n = int(input())
	ans = 0
	while n % 5 == 0:
		ans += 1
		n = 4 * n // 5
	while n % 3 == 0:
		ans += 1
		n = 2 * n // 3
	while n % 2 == 0:
		ans += 1
		n //= 2
	if n != 1:
		print(-1)
	else:
		print(ans)


q = int(input())
v = []
for i in range(q):
	a = int(input())
	f = True
	c = 0
	while a != 1:
		c += 1
		if a % 2 == 0:
			a //= 2
		elif a % 3 == 0:
			a = 2 * a // 3
		elif a % 5 == 0:
			a = 4 * a // 5
		else:
			v.append(-1)
			f = False
			break
	if f:
		v.append(c)
for i in v:
	print(i)


import sys
inf = float('inf')
mod = 1000000007

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

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

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

def int1():
	return int(input())
import string
import math
from itertools import combinations

def main():
	t = int(input())
	while t > 0:
		x = int1()
		y = 0
		z = 0
		v = 0
		if x == 1:
			print('0')
			y = 1
		z1 = 9999
		while x > 1:
			r = 0
			k = 0
			w = 0
			if x % 2 == 0:
				x = x // 2
				r = 1
				z = z + 1
			if x % 3 == 0 and r != 1:
				x = x * 2 // 3
				k = 1
				z = z + 1
			if x % 5 == 0 and r != 1 and (k != 1):
				x = x * 4 // 5
				z = z + 1
				w = 1
			if x == 1:
				break
			if r == 0 and k == 0 and (w == 0):
				break
		if z >= 0 and y == 0 and (x == 1):
			print(z)
			v = 1
		elif v != 1 and y != 1 and (x != 1):
			print('-1')
		t = t - 1
main()


s = int(input())
for i in range(s):
	n = int(input())
	flag = 0
	if n == 1:
		print(0)
	else:
		count = 0
		while n != 1:
			if n % 5 == 0:
				n = 4 * n // 5
				count += 1
			elif n % 3 == 0:
				n = 2 * n // 3
				count += 1
			elif n % 2 == 0:
				n = n // 2
				count += 1
			elif n % 5 != 0 or n % 2 != 0 or n % 3 != 0:
				flag = 1
				print(-1)
				break
		if flag == 0:
			print(count)


import math
t = int(input())
while t:
	t -= 1
	n = int(input())
	m = n
	mov = 0
	while n % 5 == 0:
		mov += 3
		n = n // 5
	while n % 3 == 0:
		mov += 2
		n = n // 3
	while n % 2 == 0:
		mov += 1
		n = n // 2
	if n == 1:
		print(mov)
	else:
		print(-1)


import math
for _ in range(int(input())):
	n = int(input())
	(two, three, five) = (0, 0, 0)
	if n == 1:
		print(0)
		continue
	while n % 2 == 0:
		n //= 2
		two += 1
	while n % 3 == 0:
		n //= 3
		three += 1
	while n % 5 == 0:
		n //= 5
		five += 1
	if n != 1:
		print('-1')
	else:
		print(two + 2 * three + 3 * five)


def fn(x):
	count = 0
	while x % 5 == 0:
		count += 1
		x = 4 * x // 5
	while x % 3 == 0:
		count += 1
		x = 2 * x // 3
	while x % 2 == 0:
		count += 1
		x = x // 2
	if x == 1:
		return count
	else:
		return -1
n = int(input())
l = []
for i in range(n):
	print(fn(int(input())))


def count(x):
	c = 0
	while x % 5 == 0:
		(x, c) = (x // 5, c + 3)
	while x % 3 == 0:
		(x, c) = (x // 3, c + 2)
	while x % 2 == 0:
		(x, c) = (x // 2, c + 1)
	return c if x == 1 else -1
q = int(input())
for i in range(q):
	print(count(int(input())))


import sys
input = sys.stdin.readline
Q = int(input())
A = [int(input()) for _ in range(Q)]
for a in A:
	d = [0, 0, 0]
	while a % 2 == 0:
		d[0] += 1
		a //= 2
	while a % 3 == 0:
		d[1] += 1
		a //= 3
	while a % 5 == 0:
		d[2] += 1
		a //= 5
	if a > 1:
		print(-1)
	else:
		print(d[0] + d[1] * 2 + d[2] * 3)


q = int(input())
out = []
for i in range(0, q):
	kq = 0
	n = int(input())
	while n % 5 == 0:
		n = n // 5
		kq = kq + 3
	while n % 3 == 0:
		n = n // 3
		kq = kq + 2
	while n % 2 == 0:
		n = n // 2
		kq = kq + 1
	if n != 1:
		out.append(-1)
	else:
		out.append(kq)
for i in range(0, q):
	print(out[i])


for _ in range(int(input())):
	n = int(input())
	cnt2 = 0
	cnt3 = 0
	cnt5 = 0
	if n == 1:
		print(0)
		continue
	if n % 2 != 0 and n % 3 != 0 and (n % 5 != 0):
		print(-1)
	else:
		y = n
		x = n
		while x % 2 == 0:
			cnt2 += 1
			x = x // 2
			y = y // 2
		x = n
		while x % 3 == 0:
			cnt3 += 1
			x = x // 3
			y = y // 3
		x = n
		while x % 5 == 0:
			cnt5 += 1
			x = x // 5
			y = y // 5
		if y == 1:
			print(cnt2 + 2 * cnt3 + 3 * cnt5)
		else:
			print(-1)


from pprint import pprint
import sys
input = sys.stdin.readline
q = int(input())
for _ in range(q):
	n = int(input())
	res = 0
	while n % 5 == 0:
		n = n // 5
		res += 3
	while n % 3 == 0:
		n = n // 3
		res += 2
	while n % 2 == 0:
		n = n // 2
		res += 1
	print(res if n == 1 else '-1')


c = 0

def f(x):
	global c
	c += 1
	if x % 2 == 0:
		return x // 2
	elif x % 3 == 0:
		c += 1
		return x // 3
	elif x % 5 == 0:
		c += 2
		return x // 5
	else:
		return -1
n = int(input())
for _ in range(n):
	c = 0
	r = int(input())
	while 1:
		if r == 1:
			print(c)
			break
		elif r == -1:
			print(-1)
			break
		r = f(r)


q = int(input())
while q > 0:
	q -= 1
	x = int(input())
	global i
	i = 0

	def change(y):
		global x
		global i
		while x % y == 0:
			x //= y
			x *= y - 1
			i += 1
	if x % 5 == 0:
		change(5)
	if x % 3 == 0:
		change(3)
	if x % 2 == 0:
		change(2)
	if x == 1:
		print(i)
	else:
		print(-1)


for i in range(int(input())):
	a = int(input())
	vs = a
	(flag, co) = (0, 0)
	while a != 1:
		if a % 2 == 0:
			co += 1
			a = a // 2
		elif a % 3 == 0:
			co += 2
			a = a // 3
		elif a % 5 == 0:
			co += 3
			a = a // 5
		else:
			flag = 1
			break
	if flag:
		print('-1')
	elif vs == 1:
		print(0)
	else:
		print(co)


a = int(input())
for i in range(a):
	b = int(input())
	cnt = 0
	if b % 2 == 0 or b % 3 == 0 or b % 5 == 0:
		while b != 1:
			if b % 2 == 0:
				b = b // 2
				cnt += 1
			elif b % 3 == 0:
				b = 2 * (b // 3)
				cnt += 1
			elif b % 5 == 0:
				b = 4 * (b // 5)
				cnt += 1
			else:
				cnt = -1
				break
		print(cnt)
	elif b == 1:
		print('0')
	else:
		print('-1')


q = int(input())
a = [2, 3, 5]
for _ in range(q):
	n = int(input())
	N = n
	ans = 0
	while N > 1:
		ok = 0
		for x in a:
			if N % x == 0:
				N //= x
				N *= x - 1
				ans += 1
				ok = 1
				break
		if ok == 0:
			break
	print([ans, -1][N > 1])


def ans(a):
	count = 0
	while a != 1:
		if a % 5 == 0:
			a = 4 * a // 5
			count = count + 1
		elif a % 3 == 0:
			a = 2 * a // 3
			count = count + 1
		elif a % 2 == 0:
			a = a // 2
			count = count + 1
		else:
			break
	if a != 1:
		count = -1
	print(count)
for i in range(int(input())):
	a = int(input())
	ans(a)


for _ in range(int(input())):
	n = int(input())
	moves = 0
	flg = 0
	while n > 1:
		if n % 2 == 0:
			moves += 1
			n //= 2
		elif n % 3 == 0:
			moves += 1
			n //= 3
			n *= 2
		elif n % 5 == 0:
			moves += 1
			n //= 5
			n *= 4
		else:
			flg = 1
			break
	if flg:
		print(-1)
	else:
		print(moves)


def mul5(num):
	if num % 5 == 0:
		return 4 * (num // 5)

def mul2(num):
	if num % 2 == 0:
		return num // 2

def mul3(num):
	if num % 3 == 0:
		return 2 * (num // 3)
while True:
	try:
		val = int(input())
		num = [0] * val
		break
	except:
		print('this is not a valid input')
for i in range(0, val):
	num[i] = int(input())
for x in range(0, val):
	count = 0
	if num[x] == 1:
		print(0)
	else:
		while num[x] / 5 >= 1 and num[x] % 5 == 0:
			num[x] = mul5(num[x])
			count += 1
		while num[x] / 3 >= 1 and num[x] % 3 == 0:
			num[x] = mul3(num[x])
			count += 1
		while num[x] / 2 >= 1 and num[x] % 2 == 0:
			num[x] = mul2(num[x])
			count += 1
		if count > 0 and num[x] == 1:
			count = count
		else:
			count = -1
		print(count)


for _ in range(int(input())):
	(n, cnt1, cnt2, cnt3) = (int(input()), 0, 0, 0)
	while n % 2 == 0:
		n //= 2
		cnt1 += 1
	while n % 3 == 0:
		n //= 3
		cnt2 += 1
	while n % 5 == 0:
		n //= 5
		cnt3 += 1
	res = int(-1) if n != 1 else int(cnt1 + cnt2 * 2 + cnt3 * 3)
	print(res)


def divideit(i, num):
	if i == 1:
		return num
	choices = []
	if i % 2 == 0:
		choices.append(i // 2)
	if i % 3 == 0:
		choices.append(2 * i // 3)
	if i % 5 == 0:
		choices.append(4 * i // 5)
	if len(choices) == 0:
		return -1
	return divideit(min(choices), num + 1)
num = int(input())
i = 0
while i < num:
	to_devide = int(input())
	result = divideit(to_devide, 0)
	i += 1
	print(result)


INT_MAX = 10 ** 18 + 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 cal(n):
	if n == 1:
		return 0
	x = 0
	y = 0
	z = 0
	a = n
	while a % 2 == 0:
		a //= 2
		x += 1
	b = n
	while b % 3 == 0:
		b //= 3
		y += 1
	c = n
	while c % 5 == 0:
		c //= 5
		z += 1
	if 2 ** x * 3 ** y * 5 ** z != n:
		return -1
	else:
		return x + 2 * y + 3 * z
for _ in range(int(input())):
	n = int(input())
	print(cal(n))


def main():
	q = int(input())
	for request in range(q):
		n = int(input())
		counter = 0
		while n != 1:
			counter += 1
			if n % 2 == 0:
				n //= 2
			elif n % 3 == 0:
				n = n * 2 // 3
			elif n % 5 == 0:
				n = n * 4 // 5
			else:
				counter = -1
				break
		print(counter)
main()


q = int(input())
for i in range(0, q):
	ans = 0
	n = int(input())
	while (n % 2 == 0 or n % 3 == 0 or n % 5 == 0) and n != 1:
		if n % 2 == 0:
			n = n // 2
		elif n % 3 == 0:
			n = 2 * n // 3
		else:
			n = 4 * n // 5
		ans += 1
	if n == 1:
		print(ans)
	else:
		print(-1)


def to(n):
	if n == 1:
		return 0
	c = 0
	while n > 1:
		if n % 2 == 0:
			n = n // 2
			c += 1
		elif n % 3 == 0:
			n = n // 3 * 2
			c += 1
		elif n % 5 == 0:
			n = n // 5 * 4
			c += 1
		else:
			return -1
			break
	return c
for _ in range(int(input())):
	n = int(input())
	print(to(n))


R = lambda : map(int, input().split())
l = []
t = int(input())
for _ in range(t):
	n = int(input())
	l.append(n)
for i in range(t):
	ct = 0
	while l[i] != 1:
		if l[i] % 2 == 0:
			l[i] //= 2
			ct += 1
		elif l[i] % 3 == 0:
			l[i] = 2 * (l[i] // 3)
			ct += 1
		elif l[i] % 5 == 0:
			l[i] = 4 * (l[i] // 5)
			ct += 1
		else:
			print('-1')
			break
	if l[i] == 1:
		print(ct)


for i in range(int(input())):
	n = int(input())
	count = 0
	flag = True
	while n > 1 and flag:
		if n % 2 == 0:
			n = n // 2
			count += 1
			continue
		elif n % 5 == 0:
			n = 4 * n // 5
			count += 1
			continue
		elif n % 3 == 0:
			n = 2 * n // 3
			count += 1
			continue
		flag = False
	if n == 1:
		print(count)
	else:
		print('-1')


def main():
	n = int(input())
	for _ in range(n):
		divide(int(input()))

def divide(n):
	counter = 0
	while n != 1:
		if n % 5 == 0:
			n = n // 5
			counter += 3
		elif n % 3 == 0:
			n = n // 3
			counter += 2
		elif n % 2 == 0:
			n = n // 2
			counter += 1
		else:
			counter = -1
			n = 1
	print(counter)
main()


m = int(input())
for _ in range(m):
	n = int(input())
	count = 0
	flag = 0
	while n > 1:
		if n % 2 == 0:
			n = n // 2
		elif n % 3 == 0:
			n = 2 * (n // 3)
		elif n % 5 == 0:
			n = 4 * (n // 5)
		else:
			print(-1)
			flag = 1
			break
		count += 1
	if flag == 0:
		print(count)


q = int(input())
for query in range(q):
	n = int(input())
	ANS = 0
	while n > 1:
		if n % 3 == 0:
			ANS += 1
			n = n // 3 * 2
		elif n % 5 == 0:
			ANS += 1
			n = n // 5 * 4
		elif n % 2 == 0:
			ANS += 1
			n //= 2
		else:
			print(-1)
			break
	else:
		print(ANS)


t1 = int(input())
for _ in range(t1):
	a = int(input())
	c = 0
	while a % 2 == 0:
		a //= 2
		c += 1
	while a % 3 == 0:
		a //= 3
		c += 2
	while a % 5 == 0:
		a //= 5
		c += 3
	if a == 1:
		print(c)
	else:
		print(-1)


t = int(input())
l = []
while t:
	sum = 0
	n = int(input())
	flag = 0
	while n != 1:
		if n % 2 == 0:
			n = n // 2
			sum += 1
		elif n % 3 == 0:
			n = 2 * n // 3
			sum += 1
		elif n % 5 == 0:
			n = 4 * n // 5
			sum += 1
		else:
			flag = 1
			break
	if flag == 1:
		print(-1)
	else:
		print(sum)
	t -= 1


q = int(input())
for qt in range(q):
	(cnt5, cnt2, cnt3, cnt) = (0, 0, 0, 0)
	n = int(input())
	if n == 1:
		print(0)
		continue
	while n % 5 == 0:
		n //= 5
		cnt5 += 1
		n *= 4
	while n % 3 == 0:
		n //= 3
		cnt3 += 1
		n *= 2
	while n % 2 == 0:
		n //= 2
		cnt2 += 1
	if n == 1:
		print(cnt2 + cnt3 + cnt5)
	else:
		print(-1)


nu = int(input())
numbers = []
for i in range(nu):
	inp = input()
	if inp == '':
		break
	numbers.append(int(inp))
valid_multiplication = 0
number_of_timers = 0
counter = 0
bool = True
for number in numbers:
	counter = 0
	bool = True
	while bool == True:
		bool = False
		valid_multiplication = 0
		if number % 2 == 0:
			counter += 1
			number //= 2
			bool = True
			valid_multiplication += 1
		elif number % 3 == 0:
			counter += 1
			number = number // 3 * 2
			bool = True
			valid_multiplication += 1
		elif number % 5 == 0:
			counter += 1
			number = number // 5 * 4
			bool = True
			valid_multiplication += 1
		if number == 1:
			valid_multiplication += 1
			number_of_timers = counter
			print(number_of_timers)
			bool = False
		if valid_multiplication == 0:
			number_of_timers = -1
			print(number_of_timers)
			break


def check(n):
	rez = 0
	while n % 5 == 0:
		n //= 5
		rez += 3
	while n % 3 == 0:
		n //= 3
		rez += 2
	while n % 2 == 0:
		n //= 2
		rez += 1
	if n == 1:
		return rez
	else:
		return -1
n = int(input())
for i in range(n):
	r = int(input())
	print(check(r))


def po(n):
	count = 0
	while n != 1:
		if n % 2 == 0:
			count += 1
			n = n // 2
		elif n % 3 == 0:
			count += 2
			n = n // 3
		elif n % 5 == 0:
			count += 3
			n = n // 5
		else:
			print(-1)
			return 0
	print(count)
T = int(input())
for i in range(T):
	n = int(input())
	po(n)


import sys
input = sys.stdin.readline
from math import log2, log, ceil

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 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):
	while x != link[x]:
		x = link[x]
	return x

def union(x, y, size, link):
	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())):
	n = int(input())
	count = 0
	while n % 2 == 0 or n % 3 == 0 or n % 5 == 0:
		if n % 2 == 0:
			count += 1
			n //= 2
		elif n % 3 == 0:
			count += 1
			n //= 3
			n *= 2
		elif n % 5 == 0:
			count += 1
			n //= 5
			n *= 4
	if n == 1:
		print(count)
	else:
		print(-1)


q = int(input())
for tc in range(0, q):
	n = int(input())
	moves = 0
	while n > 1:
		if n % 2 == 0:
			n = n // 2
			moves += 1
		elif n % 3 == 0:
			n = n // 3
			moves += 2
		elif n % 5 == 0:
			n = n // 5
			moves += 3
		else:
			moves = -1
			break
	print(moves)


from decimal import Decimal
n = int(input(''))
a = []
for index in range(n):
	count = 0
	x = Decimal(input(''))
	while x != 1:
		if x % 2 == 0:
			x = x / 2
			count += 1
		elif x % 3 == 0:
			x = x * 2 / 3
			count += 1
		elif x % 5 == 0:
			x = x * 4 / 5
			count += 1
		else:
			count = -1
			x = 1
	a.append(count)
for index in range(len(a)):
	print(a[index])


ch = 0

def lala(x):
	global ch
	tmp = 0
	if x % 2 == 0:
		ch += 1
		tmp = x // 2
	elif x % 3 == 0:
		ch += 2
		tmp = x // 3
	elif x % 5 == 0:
		ch += 3
		tmp = x // 5
	else:
		tmp = -1
	return tmp
n = int(input())
for _ in range(n):
	ch = 0
	v = int(input())
	while 1:
		if v == -1:
			ch = -1
			break
		if v == 1:
			break
		v = lala(v)
	print(ch)


a = int(input())
u = []
for i in range(a):
	x = int(input())
	t = 0
	while x > 1:
		if x % 2 == 0:
			x = x // 2
		elif x % 3 == 0:
			x = x // 3 * 2
		elif x % 5 == 0:
			x = x // 5 * 4
		else:
			x = 0
			t = -2
		t += 1
	u.append(t)
for i in range(a):
	print(u[i])


q = int(input())
for i in range(q):
	n = int(input())
	cnt = 0
	flag = 1
	while n != 1:
		if n % 2 == 0:
			n //= 2
		elif n % 3 == 0:
			n = 2 * n // 3
		elif n % 5 == 0:
			n = 4 * n // 5
		else:
			flag = 0
			break
		cnt += 1
	if flag == 1:
		print(cnt)
	else:
		print('-1')


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

def lin():
	return list(ain())

def plist(l):
	for x in l:
		print(x, end=' ')
	print()

def indexof(l, v, l3):
	return l3[v]
for _ in range(int(input())):
	n = int(input())
	c = 0
	f = 0
	while n != 1:
		if n % 2 == 0:
			n = n // 2
		elif n % 3 == 0:
			n = 2 * n // 3
		elif n % 5 == 0:
			n = 4 * n // 5
		else:
			f = 1
			print(-1)
			break
		c += 1
	if f == 0:
		print(c)


def main():
	t = int(input())
	while t:
		n = int(input())
		c = 0
		while n != 1:
			if n % 2 == 0:
				n = n // 2
			elif n % 3 == 0:
				n = 2 * n // 3
			elif n % 5 == 0:
				n = 4 * n // 5
			else:
				print('-1')
				break
			c = c + 1
		if n == 1:
			print(c)
		t = t - 1
main()


n = int(input())
while n:
	s = int(input())
	i = 0
	k = 0
	while s % 5 == 0:
		s //= 5
		i += 2
		k += 1
	while s % 3 == 0:
		s //= 3
		i += 1
		k += 1
	while s % 2 == 0:
		s //= 2
		k += 1
	if s == 1:
		k += i
		print(k)
	else:
		print(-1)
	n -= 1


for _ in range(int(input())):
	k = int(input())
	c = 0
	flag = 0
	while True:
		if k == 1:
			break
		if k % 2 == 0:
			k = k // 2
			c += 1
		elif k % 3 == 0:
			k = 2 * k // 3
			c += 1
		elif k % 5 == 0:
			k = 4 * k // 5
			c += 1
		else:
			flag = 1
			break
	if flag == 1:
		print(-1)
	else:
		print(c)


n = int(input())
L = [int(input()) for x in range(n)]

def operation(x, counter):
	if x == 1:
		print(counter)
	elif x > 0:
		counter += 1
		if x % 2 == 0:
			return operation(x // 2, counter)
		elif x % 3 == 0:
			return operation(x * 2 // 3, counter)
		elif x % 5 == 0:
			return operation(x * 4 // 5, counter)
		else:
			print('-1')
	else:
		print('-1')
for item in L:
	counter = 0
	operation(item, counter)


def main():
	q = int(input())
	for i in range(q):
		n = int(input())
		c = 0
		if n == 1:
			print(0)
		while n != 1:
			if n % 2 == 0:
				n = n // 2
			elif n % 3 == 0:
				n = 2 * n // 3
			elif n % 5 == 0:
				n = 4 * n // 5
			else:
				print('-1')
				c = 0
				break
			c += 1
		if c > 0:
			print(c)
main()


def divide(n):
	cnt = 0
	while n != 1:
		if n % 2 != 0 and n % 3 != 0 and (n % 5 != 0):
			return -1
		elif n % 2 == 0:
			n = n // 2
			cnt += 1
		elif n % 3 == 0:
			n = 2 * (n // 3)
			cnt += 1
		elif n % 5 == 0:
			n = 4 * (n // 5)
			cnt += 1
	return cnt
T = int(input())
for _ in range(T):
	n = int(input())
	print(divide(n))


q = int(input())

def moves(n):
	a = 0
	b = 0
	c = 0
	while n % 2 == 0:
		n //= 2
		a += 1
	while n % 3 == 0:
		n //= 3
		b += 1
	while n % 5 == 0:
		n //= 5
		c += 1
	if n != 1:
		return -1
	return a + 2 * b + 3 * c
for i in range(q):
	n = int(input())
	print(moves(n))


n = int(input())
for i in range(n):
	q = w = e = 0
	a = int(input())
	while a % 5 == 0:
		a //= 5
		q += 1
	while a % 3 == 0:
		a //= 3
		w += 1
	while a % 2 == 0:
		a //= 2
		e += 1
	if a > 1:
		print(-1)
	else:
		print(q + w + e + q * 2 + w)


import sys
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *
readl = lambda : list(map(int, sys.stdin.readline().split()))
readt = lambda : tuple(map(int, sys.stdin.readline().split()))
read = lambda : sys.stdin.readline().rstrip()
readi = lambda : int(read())
readmi = lambda : map(int, sys.stdin.readline().split())
readms = lambda : map(str, sys.stdin.readline().split())
n = readi()
for i in range(n):
	t = readi()
	flg = True
	count = 0
	while t > 1:
		if t == 1:
			break
		if t % 5 == 0:
			t = t * 4 // 5
		elif t % 3 == 0:
			t = t * 2 // 3
		elif t % 2 == 0:
			t = t // 2
		else:
			flg = False
			break
		count += 1
	if flg:
		print(count)
	else:
		print(-1)


n = int(input())
for i in range(n):
	temp = int(input())
	c = 0
	while temp % 2 == 0:
		temp = temp // 2
		c = c + 1
	while temp % 3 == 0:
		temp = temp // 3
		c = c + 2
	while temp % 5 == 0:
		temp = temp // 5
		c = c + 3
	if temp == 1:
		print(c)
	else:
		print('-1')


q = int(input())
lis = []
for i in range(q):
	n = int(input())
	k = 1
	count = 0
	while n != 1:
		k = n
		if n % 2 == 0:
			n = n // 2
			count += 1
		elif n % 3 == 0:
			n = n * 2 // 3
			count += 1
		elif n % 5 == 0:
			n = n * 4 // 5
			count += 1
		else:
			count = -1
			break
	lis.append(count)
for i in range(q):
	print(lis[i])


import sys
read = sys.stdin.read
readlines = sys.stdin.readlines

def main():
	q = int(input())
	for _ in range(q):
		n = int(input())
		if n == 1:
			print(0)
			continue
		r = 0
		while n > 1:
			if n % 2 == 0:
				n = n // 2
				r += 1
			elif n % 3 == 0:
				n = n * 2 // 3
				r += 1
			elif n % 5 == 0:
				n = n * 3 // 5
				r += 1
			else:
				r = -1
				break
		print(r)
main()


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
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
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))
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

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 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 ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

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

def solve():
	n = int(inp())
	a = 0
	b = 0
	c = 0
	while n % 2 ** (a + 1) == 0:
		a += 1
	n //= 2 ** a
	while n % 3 ** (b + 1) == 0:
		b += 1
	n //= 3 ** b
	while n % 5 ** (c + 1) == 0:
		c += 1
	n //= 5 ** c
	if n != 1:
		print(-1)
	else:
		print(a + b + 2 * c + b + c)
testcase(int(inp()))


for _ in range(int(input())):
	n = int(input())
	k = n
	a = b = c = 0
	while k % 2 == 0:
		k //= 2
		a += 1
	while k % 5 == 0:
		k //= 5
		b += 1
	while k % 3 == 0:
		k //= 3
		c += 1
	if k != 1:
		print(-1)
	else:
		b *= 3
		c *= 2
		print(a + b + c)


import sys, math
input = sys.stdin.readline
t = int(input())
while t > 0:
	n = int(input())
	(n2, n3, n5) = (0, 0, 0)
	while n % 5 == 0:
		n5 += 1
		n = int(4 * n // 5)
	while n % 3 == 0:
		n3 += 1
		n = int(2 * n // 3)
	while n % 2 == 0:
		n2 += 1
		n = int(n // 2)
	ans = n2 + n3 + n5
	if n != 1:
		print(-1)
	else:
		print(ans)
	t -= 1


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

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()):
	n = int(input())
	ans = 0
	while True:
		if n % 2 == 0:
			ans += 1
			n //= 2
		elif n % 3 == 0:
			ans += 1
			n = 2 * n // 3
		elif n % 5 == 0:
			ans += 1
			n = 4 * n // 5
		elif n == 1:
			break
		else:
			ans = -1
			break
	print(ans)


q = int(input())
for i in range(q):
	n = int(input())
	(k2, k3, k5) = (0, 0, 0)
	while n % 2 == 0:
		k2 += 1
		n //= 2
	while n % 3 == 0:
		k3 += 1
		n //= 3
	while n % 5 == 0:
		k5 += 1
		n //= 5
	if n == 1:
		print(k2 + 2 * k3 + 3 * k5)
	else:
		print(-1)


import math
for i in range(int(input())):
	n = int(input())
	c1 = 0
	c2 = 0
	c3 = 0
	while n % 2 == 0:
		n = n // 2
		c1 = c1 + 1
	while n % 3 == 0:
		n = n // 3
		c2 = c2 + 1
	while n % 5 == 0:
		n = n // 5
		c3 = c3 + 1
	if n == 1:
		print(int(c1 + 2 * c2 + 3 * c3))
	else:
		print('-1')


q = int(input())

def engine(n):
	temp = 0
	while n != 1:
		boo = 0
		if boo == 0 and n % 2 == 0:
			boo = 1
			n //= 2
		if boo == 0 and n % 3 == 0:
			boo = 1
			n = n * 2 // 3
		if boo == 0 and n % 5 == 0:
			boo = 1
			n = n * 4 // 5
		temp += 1
		if boo == 0:
			return -1
	return temp
for i in range(q):
	n = int(input())
	print(engine(n))


def solve():
	n = int(input())
	count = 0
	while n % 3 == 0:
		n = 2 * n // 3
		count += 1
	while n % 5 == 0:
		n = 4 * n // 5
		count += 1
	while n % 2 == 0:
		n = n // 2
		count += 1
	if n == 1:
		print(count)
	else:
		print(-1)

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


t = int(input())
while t:
	n = int(input())
	m = 0
	while n > 1:
		if n % 2 == 0:
			n = n // 2
			m += 1
			continue
		elif n % 3 == 0:
			n = 2 * n // 3
			m += 1
			continue
		elif n % 5 == 0:
			n = 4 * n // 5
			m += 1
		else:
			break
	if n == 1:
		print(m)
	else:
		print(-1)
	t -= 1


for i in range(int(input())):
	n = int(input())
	moves = 0
	while n % 2 == 0:
		n = n // 2
		moves += 1
	while n % 3 == 0:
		n = n // 3
		moves += 2
	while n % 5 == 0:
		n = n // 5
		moves += 3
	if n == 1:
		print(moves)
	else:
		print(-1)


a = int(input())
b = 0
while b < a:
	c = int(input())
	count = 0
	while c > 1:
		if c % 2 == 0:
			c //= 2
			count += 1
		elif c % 3 == 0:
			c = 2 * c // 3
			count += 1
		elif c % 5 == 0:
			c = 4 * c // 5
			count += 1
		elif c != 1:
			count = -1
			break
	print(count)
	b += 1


def lala(x):
	tmp = 0
	if x % 2 == 0:
		tmp = x // 2
	elif x % 3 == 0:
		tmp = 2 * x // 3
	elif x % 5 == 0:
		tmp = 4 * x // 5
	else:
		tmp = -1
	return tmp
n = int(input())
for i in range(n):
	v = int(input())
	tmp = 0
	while v != 1:
		v = lala(v)
		tmp += 1
		if v == -1:
			tmp = -1
			break
	print(tmp)


from sys import stdin, setrecursionlimit
import heapq
q = int(stdin.readline().strip())
while q > 0:
	ans = 0
	n = int(stdin.readline().strip())
	flag = False
	while n != 1:
		if n % 2 == 0:
			n = n // 2
			ans += 1
		elif n % 3 == 0:
			n = n // 3
			n *= 2
			ans += 1
		elif n % 5 == 0:
			n = n // 5
			n *= 4
			ans += 1
		else:
			flag = True
			break
	if flag:
		print(-1)
	else:
		print(ans)
	q -= 1


n = int(input())
count = 0
arr = []
for i in range(0, n):
	m = int(input())
	while 1:
		if m == 1:
			arr.append(count)
			break
		if m % 2 == 0:
			m = m // 2
			count += 1
		elif m % 3 == 0:
			m = 2 * m // 3
			count += 1
		elif m % 5 == 0:
			m = 4 * m // 5
			count += 1
		else:
			arr.append(-1)
			break
	count = 0
for i in range(0, n):
	print(arr[i])


q = int(input())
while q > 0:
	n = int(input())
	a = 0
	while n > 1:
		if n % 5 == 0:
			n = 4 * n // 5
			a = a + 1
		elif n % 3 == 0:
			n = 2 * n // 3
			a = a + 1
		elif n % 2 == 0:
			n = n // 2
			a = a + 1
		else:
			n = -1
	if n == -1:
		print('-1')
	else:
		print(a)
	q = q - 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 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 Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
for _ in range(int(ri())):
	n = int(ri())
	prev = n
	cnt = 0
	flag = True
	while n > 1:
		prev = n
		if n % 2 == 0:
			n = n // 2
		elif n % 3 == 0:
			n = 2 * (n // 3)
		elif n % 5 == 0:
			n = 4 * (n // 5)
		cnt += 1
		if prev == n:
			flag = False
			break
	if not flag:
		print(-1)
	else:
		print(cnt)


def division(n):
	counter = 0
	while n != 1:
		if n % 2 == 0:
			n = n // 2
		elif n % 3 == 0:
			n = 2 * n // 3
		elif n % 5 == 0:
			n = 4 * n // 5
		else:
			return -1
		counter += 1
	return counter
q = int(input())
for i in range(q):
	n = int(input())
	print(division(n))


from math import *
from collections import *
t = int(input())
for y in range(t):
	n = int(input())
	ct = 0
	while n % 5 == 0:
		n = n // 5 * 4
		ct += 1
	while n % 3 == 0:
		n = n // 3 * 2
		ct += 1
	while n % 2 == 0:
		n = n // 2
		ct += 1
	if n != 1:
		print(-1)
	else:
		print(ct)


from sys import stdin

def main():
	q = int(stdin.readline())
	for query in range(q):
		n = int(stdin.readline())
		c = 0
		while 1:
			if n % 5 != 0:
				break
			n = 4 * n // 5
			c += 1
		while 1:
			if n % 3 != 0:
				break
			n = 2 * n // 3
			c += 1
		while 1:
			if n % 2 != 0:
				break
			n = n // 2
			c += 1
		if n == 1:
			print(c)
		else:
			print(-1)
main()


n = int(input())
for _ in range(n):
	k = int(input())
	ans2 = 0
	while k % 2 == 0:
		ans2 += 1
		k = k // 2
	ans3 = 0
	while k % 3 == 0:
		ans3 += 1
		k = k // 3
	ans5 = 0
	while k % 5 == 0:
		ans5 += 1
		k = k // 5
	if k != 1:
		print(-1)
	else:
		print(ans2 + ans3 * 2 + ans5 * 3)


import os
import sys
from io import BytesIO, IOBase

def main():
	q = int(input())
	for _ in range(q):
		n = int(input())
		if n == 0:
			print(-1)
			continue
		c = 0
		while n % 2 == 0:
			n = n // 2
			c = c + 1
		while n % 3 == 0:
			n = n // 3
			c = c + 2
		while n % 5 == 0:
			n = n // 5
			c = c + 3
		if n == 1:
			print(c)
		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 step(n, count):
	if n == 1 or n == 0:
		return count
	if n % 5 == 0:
		count += 1
		return step(4 * n // 5, count)
	elif n % 2 == 0:
		count += 1
		return step(n // 2, count)
	elif n % 3 == 0:
		count += 1
		return step(2 * n // 3, count)
	else:
		return -1
t = int(input())
while t != 0:
	n = int(input())
	ans = step(n, 0)
	temp = 0
	while n != 0:
		rem = n % 10
		temp += 1
		n = n // 10
	if ans == -1:
		print(-1)
	elif temp == 2:
		print(ans)
	else:
		print(ans)
	t = t - 1


def f(n):
	s = 0
	while n % 2 == 0:
		n //= 2
		s += 1
	while n % 3 == 0:
		n //= 3
		s += 2
	while n % 5 == 0:
		n //= 5
		s += 3
	if n != 1:
		return -1
	else:
		return s
for k in range(int(input())):
	print(f(int(input())))


for j in range(int(input())):
	x = int(input())
	count = 0
	while x != 1:
		if x % 2 == 0:
			x = x // 2
			count += 1
		elif x % 3 == 0:
			x = 2 * x // 3
			count += 1
		elif x % 5 == 0:
			x = 4 * x // 5
			count += 1
		else:
			break
	if x == 1:
		print(count)
	else:
		print('-1')


def show(t):
	for _ in range(t):
		flag = 1
		count = 0
		n = int(input())
		while n >= 1:
			if n % 2 == 0:
				n = n // 2
			elif n % 3 == 0:
				n = 2 * n // 3
			elif n % 5 == 0:
				n = 4 * n // 5
			elif n == 1:
				flag = 1
				break
			else:
				flag = 0
				break
			count = count + 1
		if flag == 1 and n == 1:
			print(count)
		elif flag == 0:
			print('-1')
show(int(input()))


n = int(input())
for i in range(n):
	num = int(input())
	sum = 0
	flag = True
	while num > 1:
		if num % 2 == 0:
			num = num // 2
			sum += 1
		elif num % 3 == 0:
			num = num * 2 // 3
			sum += 1
		elif num % 5 == 0:
			num = num * 4 // 5
			sum += 1
		else:
			print(-1)
			flag = False
			break
	if flag:
		print(sum)


import sys
input = sys.stdin.readline
import math
Q = int(input())
X = [int(input()) for _ in range(Q)]

def prime(n):
	factor = {}
	for num in [2, 3, 5]:
		while n % num == 0:
			n //= num
			if not num in factor.keys():
				factor[num] = 1
			else:
				factor[num] += 1
	if n != 1:
		if not n in factor.keys():
			factor[n] = 1
		else:
			factor[n] += 1
	return factor
for N in X:
	factor = prime(N)
	ans = 0
	for (num, c) in factor.items():
		if num == 2:
			ans += c
		elif num == 3:
			ans += 2 * c
		elif num == 5:
			ans += 3 * c
		else:
			ans = -1
			break
	print(ans)


n = int(input())
for itr in range(n):
	x = int(input())
	ile2 = 0
	ile3 = 0
	ile5 = 0
	while x % 5 == 0:
		x = x // 5
		ile5 += 1
		ile2 += 2
	while x % 3 == 0:
		x = x // 3
		ile3 += 1
		ile2 += 1
	while x % 2 == 0:
		ile2 += 1
		x = x // 2
	if x > 1:
		print(-1)
	else:
		print(ile2 + ile3 + ile5)


n = int(input())
for i in range(n):
	count = 0
	x = int(input())
	while x % 5 == 0:
		count += 3
		x //= 5
	while x % 3 == 0:
		count += 2
		x //= 3
	while x % 2 == 0:
		count += 1
		x //= 2
	if x == 1:
		print(count)
	else:
		print(-1)


def divisor_count(number):
	count = 0
	while number > 1:
		if number % 2 == 0:
			count += 1
			number //= 2
		elif number % 3 == 0:
			count += 2
			number //= 3
		elif number % 5 == 0:
			count += 3
			number //= 5
		else:
			return -1
	return count
n = int(input())
for i in range(n):
	print(divisor_count(int(input())))


q = int(input())
while q:
	n = int(input())
	ans = 0
	while n % 5 == 0:
		n = n // 5
		ans += 3
	while n % 3 == 0:
		n = n // 3
		ans += 2
	while n % 2 == 0:
		n = n // 2
		ans += 1
	if n != 1:
		print(-1)
	else:
		print(ans)
	q = q - 1


n = int(input())
for i in range(n):
	k = 0
	x = int(input())
	while x != 1:
		flag = False
		for d in (2, 3, 5):
			if x % d == 0:
				x *= d - 1
				x //= d
				k += 1
				flag = True
				break
		if not flag:
			break
	if x == 1:
		print(k)
	else:
		print(-1)


n = int(input())
for i in range(n):
	count5 = 0
	count3 = 0
	count2 = 0
	aux = int(input())
	while aux % 5 == 0:
		count5 += 1
		aux = aux // 5
	while aux % 3 == 0:
		count3 += 1
		aux = aux // 3
	while aux % 2 == 0:
		count2 += 1
		aux = aux // 2
	if aux == 1:
		print(count2 + count3 * 2 + count5 * 3)
	else:
		print(-1)


from sys import stdin, stdout
q = int(stdin.readline())
while q != 0:
	n = int(stdin.readline())
	(ans2, ans3, ans5) = (0, 0, 0)
	while n % 5 == 0:
		n //= 5
		ans5 += 1
		ans2 += 2
	while n % 3 == 0:
		n //= 3
		ans2 += 1
		ans3 += 1
	while n % 2 == 0:
		n //= 2
		ans2 += 1
	if n > 1:
		print(-1)
	else:
		print(int(ans2 + ans3 + ans5))
	q -= 1


def f(x, h):
	if x == 1:
		return 0
	if x in h:
		return h[x]
	(a, b, c) = (1000000000.0, 1000000000.0, 1000000000.0)
	if x % 2 == 0:
		a = f(x // 2, h)
	elif x % 3 == 0:
		b = f(x // 3 * 2, h)
	elif x % 5 == 0:
		c = f(x // 5 * 4, h)
	else:
		return -1
	if min(a, b, c) == -1:
		h[x] = -1
	else:
		h[x] = min(a, b, c) + 1
	return h[x]
t = int(input())
while t > 0:
	n = int(input())
	if n == 1:
		print(0)
	else:
		hmap = {}
		f(n, hmap)
		if n not in hmap:
			print(-1)
		else:
			print(hmap[n])
	t -= 1


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

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

def num():
	return map(int, input().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
yp = 0

def solve():
	t = nu()
	for _ in range(t):
		n = nu()
		cc = 0
		while n != 1:
			if n % 2 == 0:
				n = n // 2
				cc += 1
				continue
			if n % 3 == 0:
				n = n * 2 // 3
				cc += 1
				continue
			if n % 5 == 0:
				n = n * 4 // 5
				cc += 1
				continue
			break
		if n == 1:
			print(cc)
		else:
			print(-1)
solve()


def divide(n):
	ans = 0
	i = 0
	while n != 1:
		if n % 2 == 0:
			n = n // 2
			ans += 1
		elif n % 3 == 0:
			n = 2 * n // 3
			ans += 1
		elif n % 5 == 0:
			n = 4 * n // 5
			ans += 1
		i += 1
		if i > 1000:
			return -1
	return ans
q = int(input())
for i in range(q):
	n = int(input())
	print(divide(n))


def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
q = int(input())
for _ in range(q):
	n = int(input())
	res = 0
	while n % 5 == 0:
		n = 4 * n // 5
		res += 1
	while n % 3 == 0:
		n = 2 * n // 3
		res += 1
	while n % 2 == 0:
		n = n // 2
		res += 1
	if n == 1:
		print(res)
	else:
		print(-1)


def main():
	answer = ''
	for i in range(int(input())):
		n = int(input())
		(twos, threes, fives) = (0, 0, 0)
		possible = True
		while n != 1:
			if n % 2 == 0:
				n //= 2
				twos += 1
			elif n % 3 == 0:
				n //= 3
				threes += 1
			elif n % 5 == 0:
				n //= 5
				fives += 1
			else:
				possible = False
				break
		if possible:
			answer += str(twos + threes * 2 + fives * 3) + '\n'
		else:
			answer += '-1 \n'
	print(answer)
main()


for _ in range(int(input())):
	n = int(input())
	c = 0
	p = 5
	x = 3
	while x:
		if not n % p:
			c += x
			n //= p
		else:
			(p, x) = (x, x - 1)
	if n != 1:
		c = -1
	print(c)


q = int(input())
for w in range(q):
	n = int(input())
	count5 = 1
	while n % 5 ** count5 == 0:
		count5 += 1
	count5 -= 1
	n = n // 5 ** count5
	n = n * 4 ** count5
	count3 = 1
	while n % 3 ** count3 == 0:
		count3 += 1
	count3 -= 1
	n = n // 3 ** count3
	n = n * 2 ** count3
	count2 = 1
	while n % 2 ** count2 == 0:
		count2 += 1
	count2 -= 1
	n = n // 2 ** count2
	ans = count2 + count5 + count3
	if n != 1:
		print(-1)
	else:
		print(ans)


n = int(input())
b = []
for i in range(n):
	(m, flag) = (0, 0)
	a = int(input())
	if a == 1:
		b.append(0)
	else:
		while a > 1:
			if a % 2 == 0:
				m += 1
				a = a // 2
			elif a % 3 == 0:
				m += 1
				a = 2 * a // 3
			elif a % 5 == 0:
				m += 1
				a = 4 * a // 5
			else:
				flag = 1
				b.append(-1)
				break
		if flag == 0:
			b.append(m)
print(*b, sep='\n')


q = int(input())
for i in range(q):
	n = int(input())
	steps = 0
	while n > 1:
		steps += 1
		(a, b, c) = (1000000000000000004, 1000000000000000004, 1000000000000000004)
		if n % 2 == 0:
			a = n // 2
		if n % 3 == 0:
			b = 2 * n // 3
		if n % 5 == 0:
			c = 4 * n // 5
		if n % 2 != 0 and n % 3 != 0 and (n % 5 != 0):
			break
		n = min(a, b, c)
	if n == 1:
		print(steps)
	else:
		print(-1)


nTest = int(input())

def shortest(n):
	ret = 0
	while n != 1:
		ret += 1
		if n % 2 == 0:
			n //= 2
		elif n % 3 == 0:
			n = n // 3 * 2
		elif n % 5 == 0:
			n = n // 5 * 4
		else:
			return -1
	return ret
for i in range(nTest):
	n = int(input())
	print(shortest(n))


import sys
from itertools import accumulate

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

def bfs(src):
	from collections import deque, defaultdict
	que = deque([(src, 0)])
	dist = defaultdict(lambda : -1)
	dist[src] = 0
	while que:
		(u, c) = que.popleft()
		if u % 2 == 0:
			v = u // 2
			if dist[v] != -1:
				continue
			dist[v] = c + 1
			que.append((v, c + 1))
		if u % 3 == 0:
			v = u // 3 * 2
			if dist[v] != -1:
				continue
			dist[v] = c + 1
			que.append((v, c + 1))
		if u % 5 == 0:
			v = u // 5 * 4
			if dist[v] != -1:
				continue
			dist[v] = c + 1
			que.append((v, c + 1))
	return dist
for _ in range(INT()):
	N = INT()
	res = bfs(N)
	print(res[1])


s = int(input())
count = 0
ans = []
while count < s:
	n = int(input())
	move = 0
	while n % 2 == 0 or n % 3 == 0 or n % 5 == 0:
		if n % 2 == 0:
			n = n // 2
			move += 1
		elif n % 3 == 0:
			n = n // 3 * 2
			move += 1
		else:
			n = n // 5 * 4
			move += 1
	if n != 1:
		ans.append(-1)
	else:
		ans.append(move)
	count += 1
for y in ans:
	print(y)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	count = 0
	while n > 1 and (n % 2 == 0 or n % 3 == 0 or n % 5 == 0):
		while n % 5 == 0:
			count += 1
			n = 4 * n // 5
		while n % 3 == 0:
			count += 1
			n = 2 * n // 3
		while n % 2 == 0:
			count += 1
			n = n // 2
	if n == 1:
		print(count)
	else:
		print(-1)


from collections import deque
for tt in range(int(input())):
	n = int(input())
	res = deque()
	if n == 1:
		res.append(0)
	else:
		cnt = 0
		while n != 1:
			if n % 2 == 0:
				n //= 2
				cnt += 1
			elif n % 3 == 0:
				n = 2 * n // 3
				cnt += 1
			elif n % 5 == 0:
				n = 4 * n // 5
				cnt += 1
			else:
				break
		if n == 1:
			res.append(cnt)
		else:
			res.append(-1)
	for i in res:
		print(i)


def get(n):
	if n == 1:
		return 0
	count = 0
	z = True
	while n != 1 and z:
		m = True
		if n % 2 == 0 and m:
			count += 1
			n = n // 2
			m = False
		elif n % 3 == 0 and m:
			count += 1
			n = n * 2 // 3
			m = False
		elif n % 5 == 0 and m:
			count += 1
			n = n * 4 // 5
			m = False
		else:
			z = False
	if z:
		return count
	else:
		return -1
n = int(input())
for i in range(n):
	m = int(input())
	print(get(m))


def minmove(n):
	if n == 1:
		return 0
	elif n % 2 == 0:
		return 1 + minmove(n // 2)
	elif n % 3 == 0:
		return 1 + minmove(2 * (n // 3))
	elif n % 5 == 0:
		return 1 + minmove(4 * (n // 5))
	else:
		return -10 ** 18
for i in range(int(input())):
	a = int(input())
	if minmove(a) < 0:
		print(-1)
	else:
		print(minmove(a))


q = int(input())
Nlist = []
for i in range(0, q):
	Nlist.append(int(input()))
for i in Nlist:
	x2 = x3 = x5 = 0
	while not i % 5:
		x5 += 1
		i = i // 5
	while not i % 3:
		x3 += 1
		i = i // 3
	while not i % 2:
		x2 += 1
		i = i // 2
	if i == 1:
		print(x2 + 2 * x3 + 3 * x5)
	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, pi

def f(n, counter=0):
	if n == 1:
		return counter
	if n % 2 == 0:
		return f(n // 2, counter + 1)
	elif n % 3 == 0:
		return f(2 * n // 3, counter + 1)
	elif n % 5 == 0:
		return f(4 * n // 5, counter + 1)
	return -1
t = int(input())
for i in range(t):
	s = int(input())
	a = f(s)
	print(a)


q = int(input())
for i in range(q):
	num = int(input())
	sub = num
	e = c = b = 0
	while sub % 5 == 0:
		sub //= 5
		e += 1
	while sub % 3 == 0:
		sub //= 3
		c += 1
	while sub % 2 == 0:
		sub //= 2
		b += 1
	if num == 1:
		print(0)
	else:
		print(-1 if sub != 1 else 2 * c + 3 * e + b)


def f(num):
	if num % 2 == 0:
		return num // 2
	elif num % 3 == 0:
		return 2 * num // 3
	elif num % 5 == 0:
		return 4 * num // 5
	else:
		return num
for i in range(int(input())):
	n = int(input())
	isum = 0
	q = f(n)
	while n != q:
		n = q
		q = f(n)
		isum += 1
	if n == 1:
		print(isum)
	else:
		print(-1)


n = int(input())
for i in range(n):
	x = int(input())
	if x == 1:
		print('0')
		continue
	lis = []
	cnt = 0
	while x != 1:
		if x % 2 == 0:
			lis.append(x // 2)
		if x % 3 == 0:
			lis.append(2 * x // 3)
		if x % 5 == 0:
			lis.append(4 * x // 5)
		if len(lis) == 0:
			break
		x = min(lis)
		cnt += 1
		lis = []
	if x == 1:
		print(cnt)
	else:
		print('-1')


for _ in range(int(input())):
	n = int(input())
	ans = 0
	while n > 1:
		while n % 2 == 0:
			n = n // 2
			ans += 1
		while n % 3 == 0:
			n = 2 * n // 3
			ans += 1
		while n % 5 == 0:
			n = 4 * n // 5
			ans += 1
		if n % 2 != 0 and n % 3 != 0 and (n % 5 != 0) and (n != 1):
			ans = -1
			break
	print(ans)


n = int(input())

def fon(t):
	c = 0
	while t != 1:
		if t % 2 == 0:
			t //= 2
			c += 1
		elif t % 3 == 0:
			t = t * 2 // 3
			c += 1
		elif t % 5 == 0:
			t = t * 4 // 5
			c += 1
		else:
			c = -1
			break
	return c
for i in range(n):
	t = int(input())
	print(fon(t))


def an(ans, n):
	if n == 1:
		return ans
	elif n % 2 == 0:
		ans += 1
		n = n // 2
		return an(ans, n)
	elif n % 3 == 0:
		ans += 1
		n = n // 3 * 2
		return an(ans, n)
	elif n % 5 == 0:
		ans += 1
		n = n // 5 * 4
		return an(ans, n)
	else:
		return -1
q = int(input())
for i in range(q):
	print(an(0, int(input())))


import math
n = int(input())
for i in range(n):
	a = int(input())
	b = [0] * 3
	while a != 1:
		if a % 2 == 0:
			a //= 2
			b[0] += 1
		elif a % 3 == 0:
			a //= 3
			b[1] += 1
		elif a % 5 == 0:
			a //= 5
			b[2] += 1
		elif a > 5:
			b[0] = -1
			b[1] = 0
			b[2] = 0
			break
	print(b[0] + b[1] * 2 + b[2] * 3)


q = int(input())
c = []
for i in range(q):
	num = int(input())
	count = 0
	while num != 1:
		if num % 2 == 0 or num % 3 == 0 or num % 5 == 0:
			if num % 2 == 0:
				n2 = num // 2
			else:
				n2 = num
			if num % 3 == 0:
				n3 = 2 * num // 3
			else:
				n3 = num
			if num % 5 == 0:
				n5 = 4 * num // 5
			else:
				n5 = num
			count += 1
			num = min(n2, n3, n5)
		else:
			count = -1
			break
	c.append(count)
for elem in c:
	print(elem)


import math
from collections import *
import sys
from functools import reduce

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

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

def get_string():
	return list(input().strip().split())

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

def printsp(*args):
	return print(*args, end=' ')
DIRECTIONS = [[0, 1], [0, -1], [1, 0], [1, -1]]
NEIGHBOURS = [(i, j) for i in range(-1, 2) for j in range(-1, 2) if i != 0 or j != 0]
OrdUnicode_a = ord('a')
OrdUnicode_A = ord('A')
CAPS_ALPHABETS = {chr(i + OrdUnicode_A): i for i in range(26)}
SMOL_ALPHABETS = {chr(i + OrdUnicode_a): i for i in range(26)}
UGLYMOD = int(1000000000.0) + 7
SEXYMOD = 998244353
MAXN = int(100000.0) + 1
for _testcases_ in range(int(input())):
	n = int(input())
	ans = 0
	while n % 5 == 0 or n % 3 == 0 or n % 2 == 0:
		if n % 5 == 0:
			n //= 5
			ans += 3
		if n % 3 == 0:
			n //= 3
			ans += 2
		if n % 2 == 0:
			n //= 2
			ans += 1
	print('-1' if n != 1 else ans)


for i in range(int(input())):
	j = 0
	k = 0
	a = int(input())
	if a == 1:
		print(0)
	else:
		while True:
			if a == 1:
				break
			elif (a % 5 == 0 or a % 3 == 0 or a % 2 == 0) and a != 1:
				if a % 5 == 0:
					a = 4 * a // 5
					j += 1
				elif a % 3 == 0:
					a = 2 * a // 3
					j += 1
				else:
					a = a // 2
					j += 1
			else:
				k = 1
				print(-1)
				break
		if k == 0:
			print(j)


z = int(input())
N = []
for x in range(z):
	N.append(int(input()))
for y in range(z):
	n = N[y]
	moves = 0
	while n % 5 == 0:
		n = n // 5
		moves += 3
	while n % 3 == 0:
		n = n // 3
		moves += 2
	while n % 2 == 0:
		n = n // 2
		moves += 1
	if n == 1:
		print(moves)
	else:
		print(-1)


memo = {}

def helper(n):
	ans = 0
	while n % 2 == 0:
		n //= 2
		ans += 1
	while n % 3 == 0:
		n //= 3
		ans += 2
	while n % 5 == 0:
		n //= 5
		ans += 3
	return ans if n == 1 else -1
q = int(input())
for _ in range(q):
	n = int(input())
	answer = helper(n)
	print(answer)


q = int(input())
for i in range(q):
	n = int(input())
	cnt = 0
	while n != 1:
		if not n % 2:
			cnt += 1
			n //= 2
			continue
		if not n % 3:
			cnt += 1
			n //= 3
			n *= 2
			continue
		if not n % 5:
			cnt += 1
			n //= 5
			n *= 4
			continue
		break
	else:
		print(cnt)
		continue
	print(-1)


Q = int(input())
while Q:
	n = int(input())
	count = 0
	flag = 0
	while n != 1:
		if n % 2 == 0:
			n = n // 2
			count += 1
		elif n % 3 == 0:
			n = 2 * n // 3
			count += 1
		elif n % 5 == 0:
			n = 4 * n // 5
			count += 1
		else:
			flag = 1
			break
	if flag == 1:
		print('-1')
	else:
		print(count)
	Q -= 1


for caso in range(int(input())):
	n = int(input())
	cont = 0
	while n != 1:
		if n % 2 == 0:
			n //= 2
			cont += 1
		elif n % 3 == 0:
			n = 2 * n // 3
			cont += 1
		elif n % 5 == 0:
			n = 4 * n // 5
			cont += 1
		else:
			cont = -1
			break
	print(cont)


def Input(n, Arr):
	n = int(input())
	for i in range(n):
		Arr.append(int(input()))
	return (n, Arr)

def Processing(n, Arr):
	for i in range(n):
		tmp = Arr[i]
		result = 0
		bl = True
		while tmp != 1:
			if tmp % 2 == 0:
				result += 1
				tmp = tmp // 2
				continue
			if tmp % 3 == 0:
				result += 2
				tmp = tmp // 3
				continue
			if tmp % 5 == 0:
				result += 3
				tmp = tmp // 5
				continue
			if tmp != 1:
				bl = False
				break
		if bl == True:
			print(result, end='\n')
		else:
			print(-1, end='\n')
n = 0
Arr = []
(n, Arr) = Input(n, Arr)
Processing(n, Arr)


for _ in range(int(input())):
	n = int(input())
	count = 0
	var = None
	while n > 1:
		var = 0
		if n % 2 == 0:
			n = n // 2
			var += 1
		elif n % 3 == 0:
			n = 2 * n // 3
			var += 1
		elif n % 5 == 0:
			n = 4 * n // 5
			var += 1
		if var == 0:
			break
		count += 1
	if var == 0:
		print(-1)
	else:
		print(count)


import sys
input = lambda : sys.stdin.readline().strip()
for _ in range(int(input())):
	n = int(input())
	ans = 0
	while n % 2 == 0:
		n //= 2
		ans += 1
	while n % 3 == 0:
		n //= 3
		n *= 2
		ans += 1
	while n % 2 == 0:
		n //= 2
		ans += 1
	while n % 5 == 0:
		n //= 5
		n *= 4
		ans += 1
	while n % 2 == 0:
		n //= 2
		ans += 1
	print(ans if n == 1 else -1)


test = int(input())
l = []
for i in range(test):
	minmove = 0
	k = 0
	n = int(input())
	while n != 1:
		if n % 2 == 0:
			n = n // 2
			minmove = minmove + 1
		elif n % 3 == 0:
			n = 2 * n // 3
			minmove = minmove + 1
		elif n % 5 == 0:
			n = 4 * n // 5
			minmove = minmove + 1
		else:
			l.append(-1)
			k = 1
			break
	if k == 0:
		l.append(minmove)
for j in range(test):
	print(str(l[j]))


def cishu(n):
	x = 0
	while n % 2 == 0:
		n = n // 2
		x += 1
	while n % 3 == 0:
		n = n // 3
		x += 2
	while n % 5 == 0:
		n = n // 5
		x += 3
	if n == 1:
		return str(x)
	else:
		return '-1'
t = int(input())
l1 = []
for _ in range(t):
	l1.append(cishu(int(input())))
print('\n'.join(l1))


count = []

def divide(n):
	if n == 1:
		return 0
	elif n % 5 != 0 and n % 3 != 0 and (n % 2 != 0):
		return -1
	else:
		if n % 5 == 0:
			n = 4 * n // 5
			count.append(1)
		elif n % 3 == 0:
			n = 2 * n // 3
			count.append(1)
		elif n % 2 == 0:
			n = n // 2
			count.append(1)
		return divide(n)
q = int(input())
for i in range(q):
	a = divide(int(input()))
	if a == -1:
		print(-1)
		count.clear()
	else:
		print(len(count))
		count.clear()


n = int(input())
m = []
for i in range(n):
	d = int(input())
	c = 0
	while d != 1:
		if d % 2 == 0:
			d = d // 2
		elif d % 3 == 0:
			d = d // 3 * 2
		elif d % 5 == 0:
			d = d // 5 * 4
		else:
			break
		c += 1
	if d == 1:
		m.append(c)
	else:
		m.append(-1)
for i in m:
	print(i)


try:
	for _ in range(int(input())):
		n = int(input())
		notone = 0
		ct = 0
		if n == 0:
			print(-1)
			continue
		while n > 1:
			if n % 2 == 0:
				n //= 2
				ct += 1
			elif n % 3 == 0:
				n = n * 2 // 3
				ct += 1
			elif n % 5 == 0:
				n = n * 4 // 5
				ct += 1
			else:
				notone = 1
				break
			if n == 1:
				break
		if notone == 1:
			print(-1)
		else:
			print(ct)
except EOFError:
	pass


n = int(input())
for i in range(0, n):
	p = int(input())
	G = 0
	C = 0
	while p != 1:
		if p % 2 == 0:
			p = p // 2
		elif p % 3 == 0:
			p = 2 * p // 3
		elif p % 5 == 0:
			p = 4 * p // 5
		else:
			G = 1
			break
		C += 1
	if G == 1:
		print(-1)
	else:
		print(C)


for _ in range(int(input())):
	n = int(input())
	(c1, c2, c3) = (0, 0, 0)
	while True:
		if n % 2 == 0:
			c1 += 1
			n = n // 2
		else:
			break
	while True:
		if n % 3 == 0:
			c2 += 1
			n = n // 3
		else:
			break
	while True:
		if n % 5 == 0:
			c3 += 1
			n = n // 5
		else:
			break
	if n != 1:
		print(-1)
	else:
		print(c1 + 2 * c2 + 3 * c3)


def solve(n):
	ctr = 0
	num = n
	n = int(n)
	while n != 1:
		ctr += 1
		if isDivisibleBy2(num):
			n = n // 2
		elif isDivisibleBy3(num):
			n = n // 3 * 2
		elif isDivisibleBy5(num):
			n = n // 5 * 4
		else:
			ctr = -1
			break
		num = str(n)
	return ctr

def isDivisibleBy3(n):
	s = sum([int(char) for char in n])
	return s % 3 == 0

def isDivisibleBy2(n):
	last_digit = int(n[-1])
	return last_digit % 2 == 0

def isDivisibleBy5(n):
	last_digit = int(n[-1])
	return last_digit % 5 == 0
q = int(input())
for _ in range(q):
	n = input()
	print('%d' % solve(n))


count = int(input())
for i in range(count):
	score = 0
	n = int(input())
	while n != 1:
		if not n % 2:
			n //= 2
		elif not n % 3:
			n //= 3
			n *= 2
		elif not n % 5:
			n //= 5
			n *= 4
		else:
			print(-1)
			break
		score += 1
	else:
		print(score)


def check(n, k=0):
	if n == 1:
		return [1, 0]
	while n % 2 == 0 or n % 3 == 0 or n % 5 == 0:
		(n, k) = cropp(n, k)
	else:
		return [n, k]

def cropp(n, k=0):
	while n % 2 == 0:
		n //= 2
		k += 1
	while n % 3 == 0:
		n //= 3
		n *= 2
		k += 1
	while n % 5 == 0:
		n //= 5
		n *= 4
		k += 1
	return [n, k]
d = []
k = int(input())
for i in range(k):
	n = int(input())
	a = []
	a = check(n)
	if a[0] == 1:
		d.append(str(a[1]))
	else:
		d.append('-1')
print('\n'.join(d))


for _ in ' ' * int(input()):
	n = int(input())
	p = 0
	while (n % 2 == 0 or n % 5 == 0) or n % 3 == 0:
		while n % 5 == 0:
			n = n - n // 5
			p += 1
		while n % 3 == 0:
			n = n - n // 3
			p = p + 1
		while n % 2 == 0:
			n = n - n // 2
			p += 1
	print('-1' if n != 1 else p)


def one():
	digit = int(input())
	if digit == 1:
		return 0
	ans = 0
	while digit != 1:
		if not digit % 5:
			ans += 3
			digit //= 5
		elif not digit % 3:
			ans += 2
			digit //= 3
		elif not digit % 2:
			ans += 1
			digit //= 2
		else:
			return -1
	return ans

def main():
	count = int(input())
	for i in range(count):
		print(one())
main()


x = int(input())
l = []
for i in range(x):
	n = int(input())
	count = 0
	if n == 1:
		print(count)
	else:
		while n != 1:
			if n % 2 == 0:
				n = n // 2
				count += 1
			elif n % 3 == 0:
				n = 2 * n // 3
				count += 1
			elif n % 5 == 0:
				n = 4 * n // 5
				count += 1
			else:
				count = -1
				break
		l.append(count)
for i in l:
	print(i)


def cnt(n):
	moves = 0
	if n == 1:
		return 0
	if n == 0:
		return -1
	else:
		while True:
			if n == 1:
				return moves
			if n % 5 == 0:
				n = n // 5
				moves += 3
				continue
			if n % 3 == 0:
				n = n // 3
				moves += 2
				continue
			if n % 2 == 0:
				n = n // 2
				moves += 1
				continue
			elif n != 1:
				return -1
for case in range(int(input())):
	n = int(input())
	print(cnt(n))


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 + 1)]
	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 maxSubArraySum(a, size):
	maxint = 10 ** 10
	max_so_far = -maxint - 1
	max_ending_here = 0
	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 solve():
	n = int(input())
	op = 0
	if n == 1:
		print(0)
		return
	while True:
		if n % 2 == 0:
			op += 1
			n = n // 2
		elif n % 3 == 0:
			op += 1
			n = 2 * n // 3
		elif n % 5 == 0:
			op += 1
			n = 4 * n // 5
		else:
			break
	if n == 1:
		print(op)
		return
	print(-1)
t = 1
t = int(input())
for _ in range(t):
	solve()


import math
t = int(input())
for _ in range(t):
	ans = 1
	counter = 0
	n = int(input())
	while n % 3 == 0 or n % 5 == 0:
		if n % 3 == 0:
			n = n // 3
			counter += 2
		if n % 5 == 0:
			n = n // 5
			counter += 3
	if math.log(n, 2) == int(math.log(n, 2)):
		print(counter + int(math.log(n, 2)))
	else:
		print(-1)


t = int(input())
s = []
for hfvjv in range(0, t):
	n = int(input())
	g = 0
	k = [0, 0, 0]
	jj = [1, 1, 1]
	while k != jj:
		if n % 5 == 0:
			n = n // 5
			g += 3
		else:
			k[2] = 1
		if n % 3 == 0:
			n = n // 3
			g += 2
		else:
			k[1] = 1
		if n % 2 == 0:
			n = n // 2
			g += 1
		else:
			k[0] = 1
	if n == 1:
		s.append(g)
	else:
		s.append(-1)
for i in s:
	print(i)


q = int(input())
for i in range(q):
	x = int(input())
	l = 0
	while 1:
		if x % 2 == 0:
			x //= 2
		elif x % 3 == 0:
			x = 2 * x // 3
		elif x % 5 == 0:
			x = 4 * x // 5
		elif x == 1:
			break
		else:
			l = -1
			break
		l += 1
	print(l)


for i in range(0, int(input())):
	num = int(input())
	onum = num
	times = 0
	while True:
		if num == 1:
			break
		elif num % 2 == 0:
			num //= 2
			times += 1
		elif num % 3 == 0:
			num //= 3
			times += 2
		elif num % 5 == 0:
			num //= 5
			times += 3
		else:
			times = -1
			break
	print(times)


n = int(input())
for _ in range(n):
	x = int(input())
	if x == 0:
		print(-1)
		continue
	cnt = 0
	while x % 5 == 0:
		x = x // 5 * 4
		cnt += 1
	while x % 3 == 0:
		x = x // 3 * 2
		cnt += 1
	while x > 1 and x % 2 == 0:
		x = x // 2
		cnt += 1
	if x == 1:
		print(cnt)
	else:
		print(-1)


def pasos(k, count):
	if k == 1:
		return count
	elif k % 2 == 0:
		return pasos(k // 2, count + 1)
	elif k % 3 == 0:
		return pasos(2 * k // 3, count + 1)
	elif k % 5 == 0:
		return pasos(4 * k // 5, count + 1)
	else:
		return -1
n = int(input())
for i in range(n):
	k = int(input())
	print(pasos(k, 0))


def getOperations(n):
	fat2 = 0
	while n % 2 == 0:
		fat2 += 1
		n //= 2
	fat3 = 0
	while n % 3 == 0:
		fat3 += 1
		n //= 3
	fat5 = 0
	while n % 5 == 0:
		fat5 += 1
		n //= 5
	if n != 1:
		return -1
	return fat2 + 2 * fat3 + 3 * fat5
num_queries = int(input())
for i in range(num_queries):
	number = int(input())
	print(getOperations(number))


import math
number = int(input())
for i in range(number):
	d = int(input())
	mm = 0
	while 0 == d % 2:
		d = d // 2
		mm += 1
	while 0 == d % 3:
		d = d // 3
		mm += 2
	while 0 == d % 5:
		d = d // 5
		mm += 3
	if d != 1:
		print(-1)
	else:
		print(mm)


def solution(n):
	cnt = 0
	while n != 1:
		if n % 2 == 0:
			n //= 2
			cnt += 1
		elif n % 3 == 0:
			n = 2 * n // 3
			cnt += 1
		elif n % 5 == 0:
			n = 4 * n // 5
			cnt += 1
		else:
			return -1
	return cnt
for i in range(int(input())):
	print(solution(int(input())))


q = int(input())
i = 0
while i < q:
	n = int(input())
	count = 0
	ans = True
	while n != 1:
		if n % 2 == 0:
			n = n // 2
			count += 1
		elif n % 3 == 0:
			n = n // 3 * 2
			count += 1
		elif n % 5 == 0:
			n = n // 5 * 4
			count += 1
		else:
			ans = False
			break
	print(count if ans else -1)
	i += 1


q = int(input())
for cas in range(q):
	n = int(input())
	ans = 0
	while n != 1:
		if n % 3 == 0:
			n = n * 2 // 3
		elif n % 5 == 0:
			n = n * 4 // 5
		elif n % 2 == 0:
			n //= 2
		else:
			ans = -1
			break
		ans += 1
	print(ans)


n = int(input())
c = 0
for i in range(n):
	c = 0
	num = int(input())
	while num % 2 == 0 or num % 3 == 0 or num % 5 == 0:
		if num % 2 == 0:
			num = num // 2
			c += 1
		elif num % 3 == 0:
			num = num // 3
			c += 2
		elif num % 5 == 0:
			num = num // 5
			c += 3
	if num != 1:
		print(-1)
	else:
		print(c)


q = int(input())
for i in range(0, q):
	n = int(input())
	br2 = 0
	br3 = 0
	br5 = 0
	while n % 2 == 0:
		n //= 2
		br2 += 1
	while n % 3 == 0:
		n //= 3
		br3 += 1
	while n % 5 == 0:
		n //= 5
		br5 += 1
	if n > 1:
		print('-1')
	else:
		print(str(br2 + 2 * br3 + 3 * br5))


q = int(input())

def bib(n):
	cnt = 0
	while n > 1:
		if n % 5 and n % 3 and n % 2:
			return -1
		if n % 2 == 0:
			n //= 2
			cnt += 1
		if n % 3 == 0:
			n //= 3
			n *= 2
			cnt += 1
		if n % 5 == 0:
			n //= 5
			n *= 4
			cnt += 1
	return cnt
for i in range(q):
	print(bib(int(input())))


ll = lambda : list(map(int, input().split()))
testcases = 1
testcases = int(input())
for testcase in range(testcases):
	[n] = ll()
	step = 0
	while n != 1:
		if n & 1 == 0:
			n = n // 2
			step += 1
			continue
		elif n % 3 == 0:
			n = n // 3
			step += 2
		elif n % 5 == 0:
			n = n // 5
			step += 3
		else:
			print(-1)
			break
	else:
		print(step)


a = int(input())
r = 0
z = list()
while r < a:
	b = int(input())
	x = 0
	while b % 2 == 0 or b % 3 == 0 or b % 5 == 0:
		if b % 2 == 0:
			b = b // 2
		elif b % 3 == 0:
			b = b // 3 * 2
		elif b % 5 == 0:
			b = b // 5 * 4
		x = x + 1
	if b == 1:
		z.append(x)
	else:
		z.append(-1)
	r = r + 1
r = 0
while r < a:
	print(z[r])
	r = r + 1


q = int(input())
for t in range(q):
	n = int(input())
	ans = 0
	while True:
		if n == 1:
			print(0)
			break
		if n % 2 != 0 and n % 3 != 0 and (n % 5 != 0):
			print(-1)
			break
		while n % 2 == 0:
			n //= 2
			ans += 1
		while n % 3 == 0:
			n = 2 * n // 3
			ans += 1
		while n % 5 == 0:
			n = 4 * n // 5
			ans += 1
		if n == 1:
			print(ans)
			break


q = int(input())
for i in range(q):
	c = 0
	n = int(input())
	while n != 1:
		n1 = n
		n2 = n
		n3 = n
		if n1 % 2 == 0:
			n1 = n1 // 2
		if n2 % 3 == 0:
			n2 = 2 * n2 // 3
		if n3 % 5 == 0:
			n3 = 4 * n3 // 5
		if n % 2 != 0 and n % 3 != 0 and (n % 5 != 0) and (n != 1):
			c = -1
			break
		n = min(n1, n2, n3)
		c += 1
	print(c)


from sys import stdin, stdout
q = int(input())
for _ in range(q):
	c = 0
	n = int(input())
	while n % 5 == 0:
		n = 4 * n // 5
		c += 1
	while n % 3 == 0:
		n = 2 * n // 3
		c += 1
	while n % 2 == 0:
		n = n // 2
		c += 1
	if n == 1:
		print(c)
	else:
		print(-1)


q = int(input())
a = []
for i in range(q):
	a.append(int(input()))

def ans(p):
	i = 0
	while p > 1:
		if p % 2 == 0:
			p = p // 2
		elif p % 3 == 0:
			p = 2 * p // 3
		elif p % 5 == 0:
			p = 4 * p // 5
		elif p != 1:
			return -1
		i += 1
	if p == 1:
		return i
for i in range(q):
	print(ans(a[i]))


q = int(input())
for i in range(q):
	x = int(input())
	c = 0
	d = 0
	while x != 1 and d == 0:
		if x % 2 == 0:
			c += 1
			x //= 2
		elif x % 3 == 0:
			c += 2
			x //= 3
		elif x % 5 == 0:
			c += 3
			x //= 5
		else:
			d += 1
	if d == 0:
		print(c)
	else:
		print('-1')


for q in range(int(input())):
	n = int(input())
	c = 0
	while n > 1:
		if n % 5 == 0:
			n = 4 * n // 5
		elif n % 3 == 0:
			n = 2 * n // 3
		elif n % 2 == 0:
			n = n // 2
		else:
			n = -1
		c += 1
	if n == 1:
		print(c)
	else:
		print('-1')


queries = int(input())
for i in range(queries):
	impossivel = False
	moves = 0
	num = int(input())
	while num > 1:
		if num % 2 == 0:
			num = num // 2
			moves += 1
		elif num % 3 == 0:
			num = 2 * num // 3
			moves += 1
		elif num % 5 == 0:
			num = 4 * num // 5
			moves += 1
		else:
			impossivel = True
			break
	if impossivel:
		print(-1)
	else:
		print(moves)


for w in range(int(input())):
	c = 0
	x = int(input())
	while x != 1:
		if x % 2 == 0:
			x = x // 2
			c += 1
		elif x % 3 == 0:
			x = x // 3 * 2
			c += 1
		elif x % 5 == 0:
			x = x // 5 * 4
			c += 1
		else:
			break
	if x == 1:
		print(c)
	else:
		print(-1)


test = int(input())
a = []
for i in range(test):
	t = int(input())
	a.append(t)
for i in range(test):
	n = a[i]
	c = 0
	k = 0
	if n == 1:
		print(0)
		continue
	while n != 1 and k == 0:
		if n % 2 == 0:
			n = n // 2
		elif n % 3 == 0:
			n = 2 * n // 3
		elif n % 5 == 0:
			n = 4 * n // 5
		else:
			print(-1)
			k = 1
		c += 1
	if k == 0:
		print(c)
	test -= 1


from sys import stdin, stdout
from itertools import combinations
from collections import defaultdict
import math
import heapq

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()
q = intIn()
for _ in range(q):
	n = intIn()
	ans = 0
	while n > 1:
		if n % 2 == 0:
			ans += 1
			n //= 2
		elif n % 3 == 0:
			ans += 1
			n = 2 * n // 3
		elif n % 5 == 0:
			ans += 1
			n = 4 * n // 5
		else:
			ans = -1
			break
	print(ans)


q = int(input())
for qq in range(q):
	x = int(input())
	ans = 0
	while x != 1:
		if x % 2 == 0:
			x //= 2
			ans += 1
		elif x % 3 == 0:
			x //= 3
			ans += 2
		elif x % 5 == 0:
			x //= 5
			ans += 3
		else:
			ans = -1
			break
	print(ans)


Q = int(input())
ans = []
for i in range(Q):
	N = int(input())
	count = 0
	while N != 1:
		if N % 2 == 0:
			N = N // 2
		elif N % 3 == 0:
			N = 2 * N // 3
		elif N % 5 == 0:
			N = 4 * N // 5
		else:
			ans.append(-1)
			break
		count += 1
	if N == 1:
		ans.append(count)
for i in ans:
	print(i)


t = int(input())
for g in range(t):
	count = 0
	n = int(input())
	result = 0
	while n > 1:
		if n % 2 == 0:
			n = n // 2
			count += 1
		elif n % 3 == 0:
			n = 2 * n // 3
			count += 1
		elif n % 5 == 0:
			n = n * 4 // 5
			count += 1
		else:
			result = 1
			break
	if result == 1:
		print(-1)
	else:
		print(count)


const = {30: [8, 30, 3], 15: [8, 15, 2], 10: [4, 10, 2], 6: [1, 3, 2], 5: [4, 5, 1], 3: [2, 3, 1], 2: [1, 2, 1]}
q = int(input())
for _ in range(q):
	n = int(input())
	if n == 1:
		print(0)
	else:
		k = 0
		for x in const.keys():
			while n % x == 0:
				n *= const[x][0]
				n //= const[x][1]
				k += const[x][2]
		if n == 1:
			print(k)
		else:
			print(-1)


import sys, math, queue, bisect
MOD = 10 ** 9 + 7
sys.setrecursionlimit(1000000)
for _ in range(int(input())):
	n = int(input())
	ans = 0
	while n > 1:
		done = False
		while n % 5 == 0:
			ans += 1
			n = 4 * (n // 5)
			done = True
		while n % 3 == 0:
			ans += 1
			n = 2 * (n // 3)
			done = True
		while n % 2 == 0:
			ans += 1
			n = n // 2
			done = True
		if not done:
			break
	if n == 1:
		print(ans)
	else:
		print(-1)


import sys, collections, math

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

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

def input():
	return sys.stdin.readline().strip()
mod = 1000000007
for _ in range(int(input())):
	n = int(input())
	if n == 1:
		print(0)
		continue
	c = 0
	flag = True
	while n != 1:
		if n % 2 == 0:
			n //= 2
			c += 1
			continue
		if n % 3 == 0:
			n = 2 * n // 3
			c += 1
			continue
		if n % 5 == 0:
			n = 4 * n // 5
			c += 1
			continue
		flag = False
		break
	if flag:
		print(c)
	else:
		print(-1)


n = int(input())
while n > 0:
	m = int(input())
	count = 0
	while m % 5 == 0:
		m //= 5
		count += 3
	while m % 3 == 0:
		m //= 3
		count += 2
	while m % 2 == 0:
		m //= 2
		count += 1
	if m == 1:
		print(count)
	else:
		print(-1)
	n -= 1


q = int(input())
for i in range(q):
	n = int(input())
	two = 0
	while n % 2 == 0:
		n //= 2
		two += 1
	three = 0
	while n % 3 == 0:
		n //= 3
		three += 1
	fife = 0
	while n % 5 == 0:
		n //= 5
		fife += 1
	if n != 1:
		print(-1)
	else:
		print(two + three * 2 + fife * 3)


t = int(input())
while t > 0:
	n = int(input())
	(count, count1, count2) = (0, 0, 0)
	while n % 2 == 0:
		n = n // 2
		count += 1
	while n % 3 == 0:
		n = n // 3
		count1 += 1
	while n % 5 == 0:
		n = n // 5
		count2 += 1
	if n != 1:
		print(-1)
	else:
		print(count + 2 * count1 + 3 * count2)
	t -= 1


def solve(n):
	c = 0
	while n != 1:
		if n % 2 == 0:
			n //= 2
			c += 1
		elif n % 3 == 0:
			n //= 3
			c += 2
		elif n % 5 == 0:
			n //= 5
			c += 3
		else:
			return -1
	return c
t = int(input())
while t:
	n = int(input())
	print(solve(n))
	t -= 1


numberOfNumbers = int(input())
counter = 0
for i in range(numberOfNumbers):
	number = int(input())
	while number % 2 == 0 or number % 3 == 0 or number % 5 == 0:
		while number % 2 == 0:
			number = number // 2
			counter += 1
		while number % 3 == 0:
			number = number * 2 // 3
			counter += 1
		while number % 5 == 0:
			number = number * 4 // 5
			counter += 1
	if number != 1:
		counter = -1
	print(counter)
	counter = 0


def rearrange(n):
	if n == 1:
		return 0
	op = 0
	num = n
	while num != 1:
		if num % 2 == 0:
			num = int(num // 2)
			op += 1
		elif num % 3 == 0:
			op += 1
			num = int(2 * num // 3)
		elif num % 5 == 0:
			op += 1
			num = int(4 * num // 5)
		else:
			return -1
	return op
nd = input().split()
n = int(nd[0])
a = [0] * n
for i in range(0, n):
	a[i] = int(input().rstrip())
for item in a:
	result = rearrange(item)
	print(result)


def fun(n):
	if n % 2 == 0:
		return n // 2
	elif n % 3 == 0:
		return 2 * n // 3
	elif n % 5 == 0:
		return 4 * n // 5
	else:
		return 0
t = int(input())
while t > 0:
	x = int(input())
	c = 0
	if x == 1:
		print(0)
	else:
		while x != 1 and x != 0:
			x = fun(x)
			c += 1
		if x == 1:
			print(c)
		if x == 0:
			print(-1)
	t -= 1


for _ in [0] * int(input()):
	(n, i) = (int(input()), 0)
	for (x, y) in ((2, 1), (3, 2), (5, 3)):
		while n % x == 0:
			n //= x
			i += y
	print((i, -1)[n > 1])


t = int(input())
for z in range(t):
	n = int(input())
	(count, flag) = (0, True)
	while n > 1:
		if n % 5 == 0:
			n = int(4 * n // 5)
			count += 1
		elif n % 3 == 0:
			n = int(2 * n // 3)
			count += 1
		elif n % 2 == 0:
			n = int(n // 2)
			count += 1
		else:
			print('-1')
			flag = False
			break
	if flag:
		print(count)


a = int(input())
b = []
k = 0
for i in range(0, a):
	b.append(int(input()))
for j in b:
	k = 0
	while True:
		if j % 2 == 0:
			j = j // 2
			k += 1
		elif j % 3 == 0:
			j = j // 3
			k += 2
		elif j % 5 == 0:
			j = j // 5
			k += 3
		else:
			break
	if j == 1:
		print(k)
	if j != 1:
		print(-1)


q = int(input())
for i in range(q):
	x = int(input())
	flag = 1
	kol = 0
	while x > 1 and flag:
		flag = 0
		if x % 2 == 0:
			kol += 1
			x //= 2
			flag = 1
	flag = 1
	while x > 1 and flag:
		flag = 0
		if x % 3 == 0:
			kol += 2
			x //= 3
			flag = 1
	flag = 1
	while x > 1 and flag:
		flag = 0
		if x % 5 == 0:
			kol += 3
			x //= 5
			flag = 1
	if x > 1:
		print(-1)
	else:
		print(kol)


import sys

class ADivideIt:

	def solve(self):
		for _ in range(int(input())):
			n = int(input())
			cnt = 0
			while n != 1:
				if n % 2 == 0:
					n //= 2
				elif n % 3 == 0:
					n //= 3
					n *= 2
				elif n % 5 == 0:
					n *= 4
					n //= 5
				else:
					print(-1)
					break
				cnt += 1
			else:
				print(cnt)
solver = ADivideIt()
input = sys.stdin.readline
solver.solve()


def solve(n, d):
	if n in d:
		return d[n]
	if n % 2 == 0:
		result = solve(n // 2, d)
		if result == -1:
			d[n] = -1
		else:
			d[n] = result + 1
	elif n % 3 == 0:
		result = solve(n // 3, d)
		if result == -1:
			d[n] = -1
		else:
			d[n] = result + 2
	elif n % 5 == 0:
		result = solve(n // 5, d)
		if result == -1:
			d[n] = -1
		else:
			d[n] = result + 3
	else:
		d[n] = -1
	return d[n]
q = int(input())
d = {1: 0}
for i in range(q):
	n = int(input())
	solve(n, d)
	print(d[n])


qnum = int(input().strip())

def divide(n):
	count = 0
	opt = True
	while n > 1 and opt:
		if not n % 2:
			n //= 2
			count += 1
		elif not n % 3:
			n //= 3
			n *= 2
			count += 1
		elif not n % 5:
			n //= 5
			n *= 4
			count += 1
		else:
			opt = False
	if not opt:
		return -1
	return count
for q in range(qnum):
	n = int(input().strip())
	count = divide(n)
	print(count)


list1 = []
q = int(input().strip())
while q:
	q -= 1
	n = int(input().strip())
	cnt = 0
	while n != 1:
		cnt += 1
		if n % 2 == 0:
			n = n // 2
		elif n % 3 == 0:
			n = n * 2 // 3
		elif n % 5 == 0:
			n = n * 4 // 5
		else:
			cnt = -1
			break
	list1.append(cnt)
for i in range(len(list1)):
	print(list1[i])


import sys
sys.setrecursionlimit(10 ** 5 + 1)
inf = int(10 ** 20)
max_val = inf
min_val = -inf
RW = lambda : sys.stdin.readline().strip()
RI = lambda : int(RW())
RMI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
RWI = lambda : [x for x in sys.stdin.readline().strip().split()]
nb_test = RI()
for _ in range(nb_test):
	curr = RI()
	counts = 0
	while curr % 5 == 0:
		counts += 3
		curr //= 5
	while curr % 3 == 0:
		counts += 2
		curr //= 3
	while curr % 2 == 0:
		counts += 1
		curr //= 2
	if curr > 1:
		print(-1)
	else:
		print(counts)


q = int(input())
for i in range(q):
	n = int(input())
	(t2, t3, t5) = (0, 0, 0)
	while n % 2 == 0:
		n = n // 2
		t2 += 1
	while n % 3 == 0:
		n = n // 3
		t3 += 1
	while n % 5 == 0:
		n = n // 5
		t5 += 1
	if n != 1:
		print(-1)
	else:
		print(t2 + t3 * 2 + t5 * 3)


def getCount(x, count):
	j = 0
	if x == 1:
		return count
	if x % 2 == 0:
		while x % 2 == 0:
			x //= 2
			count += 1
		j = getCount(x, count)
		if j:
			return j
	if x % 3 == 0:
		while x % 3 == 0:
			x = 2 * (x // 3)
			count += 1
		j = getCount(x, count)
		if j:
			return j
	if x % 5 == 0:
		while x % 5 == 0:
			x = 4 * (x // 5)
			count += 1
		j = getCount(x, count)
		if j:
			return j
	else:
		return 0
q = int(input())
for _ in range(q):
	n = int(input())
	if n == 1:
		print('0')
		continue
	j = getCount(n, 0)
	print(-1 if not j else j)


nq = int(input())
q = [int(input()) for i in range(nq)]

def check3(number):
	l = list(str(number))
	s = 0
	for i in l:
		s += int(i)
	if s % 3 == 0:
		return 'yes'
	else:
		return 'no'

def check5(number):
	if number % 10 == 5 or number % 10 == 0:
		return 'yes'
	else:
		return 'no'

def check2(number):
	if number % 2 == 0:
		return 'yes'
	else:
		return 'no'

def check_div(number):
	temp = number
	counter = 0
	if temp == 1 or temp == 0:
		print(0)
	elif temp == 2:
		print(1)
	else:
		while True:
			if check5(temp) == 'yes':
				counter += 1
				temp = 4 * temp // 5
				if temp == 5 or temp == 3 or temp == 2:
					counter += 1
					print(counter)
					break
			elif check5(temp) == 'no':
				if check3(temp) == 'yes':
					counter += 1
					temp = 2 * temp // 3
					if temp == 5 or temp == 3 or temp == 2:
						counter += 1
						print(counter)
						break
				elif check3(temp) == 'no':
					if check2(temp) == 'yes':
						counter += 1
						temp = temp // 2
						if temp == 5 or temp == 3 or temp == 2:
							counter += 1
							print(counter)
							break
					elif check2(temp) == 'no':
						print(-1)
						break
for num in q:
	check_div(num)


n = int(input())

def quant(v):
	quantidade = 0
	while v != 1 and quantidade != -1:
		if v % 2 == 0:
			v = v // 2
			quantidade = quantidade + 1
		elif v % 3 == 0:
			v = v * 2 // 3
			quantidade = quantidade + 1
		elif v % 5 == 0:
			v = v * 4 // 5
			quantidade = quantidade + 1
		else:
			quantidade = -1
	return quantidade
for i in range(n):
	print(quant(int(input())))


import sys
input = sys.stdin.readline
from collections import *
for _ in range(int(input())):
	n = int(input())
	(two, three, five) = (0, 0, 0)
	while n % 2 == 0:
		n //= 2
		two += 1
	while n % 3 == 0:
		n //= 3
		three += 1
	while n % 5 == 0:
		n //= 5
		five += 1
	if n != 1:
		print(-1)
	else:
		print(two + 2 * three + 3 * five)


for t in range(int(input())):
	n = int(input())
	(_2, _3, _5) = (0, 0, 0)
	while n:
		save = n
		if n % 2 == 0:
			_2 += 1
			n //= 2
		if n % 3 == 0:
			_3 += 1
			n //= 3
		if n % 5 == 0:
			_5 += 1
			n //= 5
		if save == n:
			break
	if n != 1:
		print('-1')
	else:
		print(_2 + _3 + _5 + _3 + _5 * 2)


queryNum = input()
queryList = []
queryNum = int(queryNum)
for i in range(queryNum):
	x = input()
	queryList.append(x)
for i in range(queryNum):
	iteration = 0
	queryList[i] = int(queryList[i])
	while queryList[i] % 5 == 0:
		queryList[i] = queryList[i] // 5
		iteration = iteration + 3
	while queryList[i] % 3 == 0:
		queryList[i] = queryList[i] // 3
		iteration = iteration + 2
	while queryList[i] % 2 == 0:
		queryList[i] = queryList[i] // 2
		iteration = iteration + 1
	if queryList[i] == 1:
		print(iteration)
	else:
		print(-1)


q = int(input())
res = 1

def f(k, op):
	global res
	if k == 1:
		res = op
		return
	if res == -1:
		return
	if k % 2 == 0:
		f(k // 2, op + 1)
	elif k % 3 == 0:
		f(2 * k // 3, op + 1)
	elif k % 5 == 0:
		f(4 * k // 5, op + 1)
	else:
		res = -1
for i in range(q):
	res = 1
	n = int(input())
	f(n, 0)
	print(res)


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
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
mod = pow(10, 9) + 7
mod2 = 998244353

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

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

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

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)]

def factorize(n):
	f = set()
	cnt = 0
	while n % 2 == 0:
		cnt += 1
		n = n // 2
	while n % 3 == 0:
		cnt += 2
		n = n // 3
	while n % 5 == 0:
		cnt += 3
		n = n // 5
	if n > 1:
		outln(-1)
		return
	outln(cnt)
for _ in range(int(data())):
	n = int(data())
	factorize(n)


n = int(input())
for i in range(n):
	a = int(input())
	b = True
	k = 0
	while b == True:
		b = False
		if a % 2 == 0:
			a = a // 2
			b = True
			k += 1
		elif a % 3 == 0:
			a = a * 2 // 3
			b = True
			k += 1
		elif a % 5 == 0:
			a = a * 4 // 5
			b = True
			k += 1
		if a == 1:
			b = False
	if a == 1:
		print(k)
	else:
		print('-1')


q = int(input())
for ii in range(q):
	n = int(input())
	n2 = 0
	ans = 0
	while n > 1:
		if n % 5 == 0:
			n //= 5
			ans += 3
		elif n % 3 == 0:
			n //= 3
			ans += 2
		elif n % 2 == 0:
			n //= 2
			ans += 1
		else:
			ans = -1
			n = 1
	print(ans)


def solve(test):
	ans = 0
	n = int(input())
	while n % 5 == 0:
		ans += 3
		n //= 5
	while n % 3 == 0:
		ans += 2
		n //= 3
	while n % 2 == 0:
		ans += 1
		n //= 2
	print(ans if n == 1 else -1)
t = 1
t = int(input())
for _ in range(t):
	solve(_ + 1)


def read_nums():
	return [int(x) for x in input().split()]

def solve(n):
	res = 0
	while True:
		if n < 1:
			return -1
		if n == 1:
			break
		elif n % 5 == 0:
			n = 4 * n // 5
			res += 1
		elif n % 3 == 0:
			n = 2 * n // 3
			res += 1
		elif n % 2 == 0:
			n = n // 2
			res += 1
		else:
			return -1
	return res

def main():
	(q,) = read_nums()
	for _ in range(q):
		print(solve(int(input())))
main()


import sys

def main():
	inp = map(int, sys.stdin.read().strip().split()[1:])
	d = {2: 1, 3: 2, 5: 3}
	out = []
	for i in inp:
		t = i
		c = 0
		for (k, v) in d.items():
			while not t % k:
				c += v
				t //= k
		out.append(t != 1 and -1 or c)
	return out
print(*main(), sep='\n')


for _ in range(int(input())):
	n = int(input())
	d = [(n, 0)]
	ans = 0
	while d:
		(n, t) = d.pop()
		if n == 1:
			ans = 1
			break
		if n % 2 == 0:
			d.append((n // 2, t + 1))
		elif n % 3 == 0:
			d.append((2 * n // 3, t + 1))
		elif n % 5 == 0:
			d.append((4 * n // 5, t + 1))
	if ans == 1:
		print(t)
	else:
		print(-1)


numeroCasos = int(input())
for i in range(numeroCasos):
	numero = int(input())
	contador = 0
	while True:
		if numero == 1:
			print(contador)
			break
		if numero % 2 == 0:
			numero = numero // 2
			contador += 1
		elif numero % 3 == 0:
			numero = 2 * numero // 3
			contador += 1
		elif numero % 5 == 0:
			numero = 4 * numero // 5
			contador += 1
		else:
			print(-1)
			break


def minnum(n):
	s = 0
	if n == 1:
		s = 0
	else:
		while n > 1:
			if n % 2 != 0 and n % 3 != 0 and (n % 5 != 0):
				s = -1
				break
			if n % 2 == 0:
				n = n // 2
				s += 1
			if n % 3 == 0:
				n = 2 * n // 3
				s += 1
			if n % 5 == 0:
				n = 4 * n // 5
				s += 1
	return s
k = []
s = int(input())
if s >= 1 and s <= 1000:
	for i in range(s):
		n = int(input())
		if n >= 1 and n <= pow(10, 18):
			k.append(minnum(n))
		else:
			k.append(-1)
for i in range(len(k)):
	print(k[i])


import sys
import math
from functools import reduce
q = int(input())
for _ in range(q):
	n = int(input())
	counter = 0
	flag = True
	while n != 1:
		if n % 2 == 0:
			n = n // 2
		elif n % 3 == 0:
			n = n * 2 // 3
		elif n % 5 == 0:
			n = n * 4 // 5
		else:
			flag = False
			break
		counter += 1
	if flag:
		print(counter)
	else:
		print(-1)


N = int(input())
for a in range(N):
	count = 0
	num = int(input())
	while num != 1:
		if num % 2 == 0:
			num //= 2
			count += 1
		elif num % 3 == 0:
			num = num * 2 // 3
			count += 1
		elif num % 5 == 0:
			num = num * 4 // 5
			count += 1
		else:
			count = -1
			break
	print(count)


n = int(input())

def check(k, sum=0):
	if k == 1:
		return sum
	elif k % 2 == 0:
		return check(k // 2, sum + 1)
	elif k % 3 == 0:
		return check(k // 3, sum + 2)
	elif k % 5 == 0:
		return check(k // 5, sum + 3)
	else:
		return -1
for i in range(n):
	num = int(input())
	print(check(num))


def fix(a):
	c = 0
	while a != 1:
		if a % 2 == 0:
			a = a // 2
			c += 1
		elif a % 3 == 0:
			a = 2 * a // 3
			c += 1
		elif a % 5 == 0:
			a = 4 * a // 5
			c += 1
		else:
			return -1
	return c

def go():
	q = int(input())
	o = ''
	for i in range(q):
		o += str(fix(int(input()))) + '\n'
	return o
print(go())


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

def solve():
	x = int(input())
	times = 0
	while x % 5 == 0:
		x = 4 * x // 5
		times += 1
	while x % 3 == 0:
		x = 2 * x // 3
		times += 1
	while x % 2 == 0:
		x = x // 2
		times += 1
	if x == 1:
		print(times)
	else:
		print(-1)
main()


import math
query = int(input())
for q in range(query):
	n = int(input())
	move = 0
	while n % 5 == 0:
		n //= 5
		move += 3
	while n % 3 == 0:
		n //= 3
		move += 2
	while n % 2 == 0:
		n //= 2
		move += 1
	if n != 1:
		print(-1)
	else:
		print(int(move))


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	if n == 1:
		print(0)
		continue
	res = 0
	doms = [2, 3, 5]
	for i in range(len(doms)):
		d = doms[i]
		while n % d == 0:
			res += 1 + i
			n //= d
	res = res if n == 1 else -1
	print(res)


import sys
input = sys.stdin.readline
q = int(input())
for i in range(q):
	n = int(input())
	res = 0
	while n != 1 and res != -1:
		if n % 2 != 0 and n % 3 != 0 and (n % 5 != 0):
			res = -1
		elif n % 2 == 0:
			n = n // 2
		elif n % 3 == 0:
			n = n * 2 // 3
		elif n % 5 == 0:
			n = n * 4 // 5
		if res != -1:
			res += 1
	print(res)


def ii(t):
	if t == 0:
		return list(map(int, input().split()))
	elif t == 1:
		return int(input())
	elif t == 2:
		return input()
p = ii(1)
for i in range(p):
	t = ii(1)
	count = 0
	ans = 0
	while t != 1:
		if t % 2 == 0:
			t = t // 2
			count = count + 1
		elif t % 3 == 0:
			t = 2 * t // 3
			count = count + 1
		elif t % 5 == 0:
			t = 4 * t // 5
			count = count + 1
		else:
			ans = -1
			break
	if ans == -1:
		print(-1)
	else:
		print(count)


q = lambda : map(int, input().split())
qi = lambda : int(input())
qs = lambda : input().split()
for _ in [0] * qi():
	c = 0
	x = qi()
	while x != 1:
		if not x % 2:
			x = x // 2
		elif not x % 3:
			x = 2 * x // 3
		elif not x % 5:
			x = 4 * x // 5
		elif x % 2 and x % 3 and x % 5:
			break
		c += 1
	if x == 1:
		print(c)
	else:
		print(-1)


q = int(input())
results = []
for i in range(q):
	n = int(input())
	result = 0
	while n > 1:
		if n % 2 == 0:
			n = n // 2
			result += 1
		elif n % 3 == 0:
			n = 2 * n // 3
			result += 1
		elif n % 5 == 0:
			n = 4 * n // 5
			result += 1
		else:
			result = -1
			break
	results.append(result)
print(*results, sep='\n')


n = int(input())
for i in range(n):
	elem = int(input())
	operations = 0
	while elem % 5 == 0:
		elem //= 5
		operations += 3
	while elem % 3 == 0:
		elem //= 3
		operations += 2
	while elem % 2 == 0:
		elem //= 2
		operations += 1
	if elem != 1:
		print(-1)
	else:
		print(operations)


import math

def check(x):
	if x == 1 or x == 2 or x == 3 or (x == 5):
		return False
	for i in range(2, int(math.sqrt(x)) + 1):
		if x % i == 0:
			return False
	return True
q = int(input())
ans = []
for i in range(q):
	x = int(input())
	k2 = 0
	k3 = 0
	k5 = 0
	while x % 2 == 0:
		x //= 2
		k2 += 1
	while x % 5 == 0:
		x //= 5
		k5 += 1
	while x % 3 == 0:
		k3 += 1
		x //= 3
	if x == 1:
		ans.append(k2 + k3 * 2 + k5 * 3)
	else:
		ans.append(-1)
for i in ans:
	print(i)


a = int(input())
ans = []
test = 0
cnt = 0
for i in range(a):
	a = int(input())
	while a > 1:
		if a % 2 == 0:
			a = a // 2
			cnt += 1
		elif a % 3 == 0:
			a = 2 * a // 3
			cnt += 1
		elif a % 5 == 0:
			a = a * 4 // 5
			cnt += 1
		else:
			cnt = -1
			break
	print(cnt)
	cnt = 0


def cal(n):
	ans = 0
	while n != 1:
		if n % 2 == 0:
			n //= 2
			ans += 1
		elif n % 3 == 0:
			n = 2 * n // 3
			ans += 1
		elif n % 5 == 0:
			n = 4 * n // 5
			ans += 1
		else:
			ans = -1
			break
	return ans
for i in range(int(input())):
	n = int(input())
	print(cal(n))


num = int(input())
queries = []
solutions = []
count = 0
const = 0
for x in range(num):
	query = int(input())
	queries.append(query)
for a in queries:
	while a != 1:
		if a % 2 == 0:
			a //= 2
			count += 1
		elif a % 3 == 0:
			a = a // 3 * 2
			count += 1
		elif a % 5 == 0:
			a = a // 5 * 4
			count += 1
		else:
			solutions.append(-1)
			const = 1
			break
	if const == 0:
		solutions.append(count)
	count = 0
	const = 0
for y in solutions:
	print(y)


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 = 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 main():
	n = I()
	a = [I() for _ in range(n)]
	r = []
	for c in a:
		t = 0
		while c > 1:
			t += 1
			if c % 2 == 0:
				c //= 2
			elif c % 3 == 0:
				c = c // 3 * 2
			elif c % 5 == 0:
				c = c // 5 * 4
			else:
				t = -1
				break
		r.append(t)
	return JA(r, '\n')
print(main())


te = int(input(''))
for _ in range(te):
	n = int(input(''))
	f = 0
	t = 0
	tw = 0
	while True:
		if n % 5 == 0:
			n = n // 5
			n = n * 4
			f += 1
		else:
			break
	while True:
		if n % 3 == 0:
			n = n // 3
			n *= 2
			t += 1
		else:
			break
	while True:
		if n % 2 == 0:
			n = n // 2
			tw += 1
		else:
			break
	if n == 1:
		print(t + tw + f)
	else:
		print(-1)


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_intList_from_str = lambda : list(map(int, list(sys.stdin.readline().strip())))
get_strList_from_str = lambda : list(sys.stdin.readline().strip())
get_int = lambda : int(sys.stdin.readline().strip())
pt = lambda x: sys.stdout.write(str(x))
n = get_int()
for _ in range(n):
	num = get_int()
	count = 0
	while num > 1:
		if num % 2 == 0:
			num = num // 2
			count += 1
		elif num % 3 == 0:
			num = 2 * num // 3
			count += 1
		elif num % 5 == 0:
			num = 4 * num // 5
			count += 1
		elif num != 1:
			count = -1
			break
		else:
			count = 0
			break
	print(count)


def main():
	c = int(input())
	vals = [int(input()) for v in range(c)]
	for v in vals:
		d = v
		r = 0
		while d != 1:
			if d % 2 == 0:
				d = d // 2
				r += 1
			elif d % 3 == 0:
				d = 2 * d // 3
				r += 1
			elif d % 5 == 0:
				d = 4 * d // 5
				r += 1
			else:
				break
		if d == 1:
			print(r)
		else:
			print(-1)
main()


t = int(input())
for test in range(t):
	n = int(input())
	cnt = 0
	flag = True
	while n > 1 or (n % 2 == 0 or n % 5 == 0 or n % 3 == 0):
		if n % 2 == 0:
			n = n // 2
			cnt += 1
		elif n % 3 == 0:
			n = 2 * n // 3
			cnt += 1
		elif n % 5 == 0:
			n = 4 * n // 5
			cnt += 1
		else:
			print(-1)
			flag = False
			break
	if flag:
		print(cnt)


for _ in range(int(input())):
	n = int(input())
	(p, q, r) = (0, 0, 0)
	while n != 1:
		if n % 2 == 0:
			p += 1
			n //= 2
		if n % 3 == 0:
			q += 1
			n //= 3
		if n % 5 == 0:
			r += 1
			n //= 5
		elif n != 1 and n % 2 != 0 and (n % 3 != 0) and (n % 5 != 0):
			print(-1)
			break
	else:
		print(p + 2 * q + 3 * r)


t = int(input())
for a0 in range(t):
	n = int(input())
	f = 0
	count = 0
	while n > 1:
		if n % 2 == 0:
			n //= 2
		elif n % 3 == 0:
			n = 2 * n // 3
		elif n % 5 == 0:
			n = 4 * n // 5
		else:
			print(-1)
			f = 1
			break
		count += 1
	if f == 0:
		print(count)


q = int(input())
for u in range(q):
	n = int(input())
	a = 0
	while n % 2 == 0:
		a += 1
		n //= 2
	while n % 3 == 0:
		a += 2
		n //= 3
	while n % 5 == 0:
		a += 3
		n //= 5
	if n > 1:
		print(-1)
	else:
		print(a)


n = int(input())
count = 0
while n > 0:
	n -= 1
	val = 0
	res = int(input())
	count = 0
	while res > 0:
		if res == 1:
			break
		if res % 2 != 0 and res % 3 != 0 and (res % 5 != 0):
			res = 0
			break
		if res % 2 == 0:
			res = res // 2
			count += 1
		if res % 3 == 0:
			res = 2 * res // 3
			count += 1
		if res % 5 == 0:
			res = 4 * res // 5
			count += 1
	if res == 1:
		print(count)
	else:
		print(-1)


T = int(input())
for i in range(T):
	n = int(input())
	count = 0
	while n % 5 == 0:
		count += 3
		n = n // 5
	while n % 3 == 0:
		count += 2
		n = n // 3
	while n % 2 == 0:
		count += 1
		n = n // 2
	if n != 1:
		count = -1
	print(count)


k = 0
t = int(input())
for j in range(t):
	a = int(input())
	while a != 1:
		if a % 5 == 0:
			k += 3
			a //= 5
		elif a % 3 == 0:
			k += 2
			a //= 3
		elif a % 2 == 0:
			a //= 2
			k += 1
		else:
			k = -1
			break
	print(k)
	k = 0


t = int(input())
for j in range(t):
	n = int(input())
	(ct, k) = (0, 0)
	while n > 1:
		if not n % 2:
			n >>= 1
		elif not n % 3:
			n //= 3
			n *= 2
		elif not n % 5:
			n //= 5
			n *= 4
		else:
			k += 1
			print(-1)
			break
		ct += 1
	if k == 0:
		print(ct)


q = int(input())
for k in range(q):
	n = int(input())
	ans = 0
	while n > 1:
		if n % 2 != 0 and n % 3 != 0 and (n % 5 != 0):
			ans = -1
			break
		if n % 5 == 0:
			n //= 5
			n *= 4
			ans += 1
		elif n % 3 == 0:
			n //= 3
			n *= 2
			ans += 1
		elif n % 2 == 0:
			n //= 2
			ans += 1
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	fats_2 = 0
	fats_3 = 0
	fats_5 = 0
	if n <= 0:
		print(-1)
		exit()
	while n % 2 == 0:
		n //= 2
		fats_2 += 1
	while n % 3 == 0:
		n //= 3
		fats_3 += 1
	while n % 5 == 0:
		n //= 5
		fats_5 += 1
	if n != 1:
		print(-1)
	else:
		ops = fats_2 + fats_3 * 2 + fats_5 * 3
		print(ops)


def count(x, ans):
	if x == 1:
		return ans
	elif x % 2 == 0 or (x % 2 == 0 and x % 3 == 0) or (x % 2 == 0 and x % 3 == 0 and (x % 5 == 0)) or (x % 2 == 0 and x % 5 == 0):
		x = x // 2
		ans += 1
		return count(x, ans)
	elif x % 3 == 0 or (x % 5 == 0 and x % 3 == 0):
		x = 2 * (x // 3)
		ans += 1
		return count(x, ans)
	elif x % 5 == 0:
		x = 4 * (x // 5)
		ans += 1
		return count(x, ans)
	elif x % 2 != 0 and x % 3 != 0 and (x % 5 != 0):
		return -1
q = int(input())
while q > 0:
	n = int(input())
	print(count(n, 0))
	q -= 1


def main():
	q = int(input())
	for _ in range(q):
		n = int(input())
		print(perform(n))

def perform(n):
	counter = 0
	while n != 1:
		if n % 2 == 0 and n % 3 == 0 and (n % 5 == 0):
			n = min(n // 2, 2 * n // 3, 4 * n // 5)
			counter += 1
		elif n % 2 == 0 and n % 3 == 0 and (n % 5 != 0):
			n = min(n // 2, 2 * n // 3)
			counter += 1
		elif n % 2 == 0 and n % 5 == 0 and (n % 3 != 0):
			n = min(n // 2, 4 * n // 5)
			counter += 1
		elif n % 5 == 0 and n % 3 == 0 and (n % 2 != 0):
			n = min(2 * n // 3, 4 * n // 5)
			counter += 1
		elif n % 5 == 0 and n % 3 != 0 and (n % 2 != 0):
			n = 4 * n // 5
			counter += 1
		elif n % 2 == 0 and n % 3 != 0 and (n % 5 != 0):
			n = n // 2
			counter += 1
		elif n % 3 == 0 and n % 2 != 0 and (n % 5 != 0):
			n = 2 * n // 3
			counter += 1
		else:
			return -1
	return counter
main()


k = int(input())
for i in range(k):
	n = int(input())
	two = three = five = 0
	while n % 2 == 0:
		n = n // 2
		two += 1
	while n % 3 == 0:
		n = n // 3
		three += 1
	while n % 5 == 0:
		n = n // 5
		five += 1
	if n != 1:
		print(-1)
	else:
		print(two + three * 2 + five * 3)


def foo(n):
	c = 0
	while n != 1:
		ok = 0
		if n % 5 == 0:
			n = 4 * n // 5
			ok = 1
		elif n % 3 == 0:
			n = 2 * n // 3
			ok = 1
		elif n % 2 == 0:
			n = n // 2
			ok = 1
		if ok == 0:
			return -1
		else:
			c = c + 1
	return c
t = int(input())
for i in range(0, t):
	n = int(input())
	ok = 0
	if n == 1:
		print(0)
	else:
		print(foo(n))


from math import *

def func(n):
	if n == 1:
		return 0
	if n % 5 == 0:
		x = func2(n, 5)
		y = n // 5 ** x
		a = func(y)
		if a == -1:
			return -1
		else:
			return a + 3 * x
	if n % 3 == 0:
		x = func2(n, 3)
		y = n // 3 ** x
		a = func(y)
		if a == -1:
			return -1
		else:
			return a + 2 * x
	if n % 2 == 0:
		x = func2(n, 2)
		y = n // 2 ** x
		if y == 1:
			return x
		else:
			return -1
	else:
		return -1

def func2(n, x):
	count = 0
	while n > 0 and n % x == 0:
		n = n // x
		count += 1
	return count
t = int(input())
for i in range(t):
	print(func(int(input())))


T = int(input())
for i in range(T):
	n = int(input())
	ans = 0
	while n > 1:
		if n % 5 == 0:
			ans += 3
			n //= 5
		elif n % 3 == 0:
			ans += 2
			n //= 3
		elif n % 2 == 0:
			ans += 1
			n //= 2
		else:
			break
	if n > 1:
		print(-1)
	else:
		print(ans)


def ff(n):
	c = 0
	while n != 1:
		if n % 2 == 0:
			n = n // 2
		elif n % 3 == 0:
			n = n * 2 // 3
		elif n % 5 == 0:
			n = n * 4 // 5
		else:
			return -1
		c += 1
	return c
for qq in range(int(input())):
	n = int(input())
	print(ff(n))


b = int(input())
for i in range(b):
	v = int(input())
	c = 0
	while v > 1:
		if v % 2 == 0:
			v = v // 2
			c += 1
		elif v % 3 == 0:
			v = 2 * v // 3
			c += 1
		elif v % 5 == 0:
			v = 4 * v // 5
			c += 1
		else:
			break
	if v == 1:
		print(c)
	else:
		print(-1)


a = []
for _ in range(int(input())):
	a.append(int(input()))
cnt_2 = 0
cnt_3 = 0
cnt_5 = 0
ans = 0
for i in range(len(a)):
	while a[i] % 5 == 0:
		a[i] //= 5
		cnt_5 += 1
	while a[i] % 3 == 0:
		a[i] //= 3
		cnt_3 += 1
	while a[i] % 2 == 0:
		a[i] //= 2
		cnt_2 += 1
	if a[i] != 1:
		ans = -1
	else:
		ans = cnt_5 * 3 + cnt_3 * 2 + cnt_2
	print(ans)
	cnt_2 = 0
	cnt_3 = 0
	cnt_5 = 0


for i in range(int(input())):
	x = int(input())
	k = 0
	fl = True
	while fl:
		fl = x % 2 == 0 or x % 3 == 0 or x % 5 == 0
		if fl:
			if x % 2 == 0:
				while x % 2 == 0:
					x //= 2
					k += 1
			elif x % 3 == 0:
				x *= 2
				x //= 3
				k += 1
			elif x % 5 == 0:
				x *= 4
				x //= 5
				k += 1
	if x != 1:
		print(-1)
	else:
		print(k)


from decimal import Decimal
for _ in range(int(input())):
	n = Decimal(input())
	counter = 0
	while n > 1:
		if n / 2 == n // 2:
			n //= 2
			counter += 1
		elif n / 3 == n // 3:
			n //= 3
			counter += 2
		elif n / 5 == n // 5:
			n //= 5
			counter += 3
		else:
			break
	print(counter if n == 1 else -1)


n = int(input())
for i in range(n):
	c = 0
	x = 0
	y = 0
	k = 0
	a = int(input())
	for i in range(a):
		if a == 1:
			break
		if a % 2 == 0:
			c += 1
			a = a // 2
		elif a % 5 == 0:
			a = a // 5
			x += 1
		elif a % 3 == 0:
			y += 1
			a = a // 3
		else:
			k = -1
			break
		k = c + 2 * y + 3 * x
	print(k)


def test(file='in.txt'):
	import sys
	sys.stdin = open(file, 'r')
	main()

def main():
	for q in range(int(input())):
		n = int(input())
		cnt = 0
		while n > 1:
			if n % 2 == 0:
				cnt += 1
				n //= 2
			elif n % 3 == 0:
				cnt += 2
				n = n // 3
			elif n % 5 == 0:
				cnt += 3
				n = n // 5
			else:
				cnt = -1
				break
		print(cnt)
main()


q = int(input())
result = []
for _ in range(q):
	n = int(input())
	count = 0
	while n != 1:
		if n % 2 == 0:
			n //= 2
		elif n % 3 == 0:
			n *= 2
			n //= 3
		elif n % 5 == 0:
			n *= 4
			n //= 5
		else:
			count = -1
			break
		count += 1
	result.append(count)
for i in range(q):
	print(result[i])


n = int(input())
for i in range(n):
	a = int(input())
	h = 0
	s = 0
	while not a == 1:
		if a % 2 == 0:
			a = a // 2
			h += 1
		if a % 3 == 0:
			a = a // 3 * 2
			h += 1
		if a % 5 == 0:
			a = a // 5 * 4
			h += 1
		if a % 2 != 0 and a % 3 != 0 and (a % 5 != 0) and (a != 1):
			print(-1)
			s = 1
			break
	if s == 0:
		print(h)


from sys import *
from fractions import *
Input = []

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

def In():
	return stdin.readline().strip()

def inputGrab():
	for line in stdin:
		Input.extend(map(str, line.strip().split()))
inputIDX = 0

def hasNext():
	global inputIDX
	return inputIDX < len(Input)

def nextInt():
	global inputIDX
	inputIDX += 1
	return int(Input[inputIDX - 1])

def nextString():
	global inputIDX
	inputIDX += 1
	return Input[inputIDX - 1]

def main():
	inputGrab()
	q = nextInt()
	for _ in range(q):
		n = nextInt()
		cnt = 0
		while n != 1:
			if n % 2 == 0:
				n = n // 2
			elif n % 3 == 0:
				n = 2 * n // 3
			elif n % 5 == 0:
				n = 4 * n // 5
			else:
				break
			cnt += 1
		if n == 1:
			print(cnt)
		else:
			print('-1')
main()


n = int(input())

def find(num):
	n = 0
	while num != 1:
		if num % 2 == 0:
			n += 1
			num = num // 2
		elif num % 3 == 0:
			n += 2
			num = num // 3
		elif num % 5 == 0:
			n += 3
			num = num // 5
		else:
			return -1
	return n
ansers = []
for i in range(0, n):
	rawInput = int(input())
	ansers.append(find(rawInput))
for item in ansers:
	print(item)


n = int(input())
a = [int(input()) for _ in range(n)]

def divide_num(num):
	index = [0, 0, 0]
	for (i, divider) in enumerate((2, 3, 5)):
		while num % divider == 0:
			num //= divider
			index[i] += 1
	return index if num == 1 else None
r = []
for num in a:
	index = divide_num(num)
	if index is None:
		r.append(-1)
	else:
		r.append(index[0] + index[1] * 2 + index[2] * 3)
print('\n'.join(map(str, r)))


queries = int(input())
for i in range(queries):
	actions = 0
	num = int(input())
	while num % 5 == 0:
		num = num * 4 // 5
		actions += 1
	while num % 3 == 0:
		num = num * 2 // 3
		actions += 1
	while num % 2 == 0:
		num //= 2
		actions += 1
	if num != 1:
		print(-1)
	else:
		print(actions)


y = int(input())
for i in range(y):
	x = int(input())
	c = 0
	f = 0
	while x != 1:
		if x % 2 != 0 and x % 3 != 0 and (x % 5 != 0):
			f = 1
			print(-1)
			break
		elif x % 5 == 0:
			x = 4 * x // 5
			c = c + 1
		elif x % 3 == 0:
			x = 2 * x // 3
			c = c + 1
		elif x % 2 == 0:
			x = x // 2
			c = c + 1
	if f != 1:
		print(c)


def sol(n):
	count = 0
	while n % 2 == 0:
		count = count + 1
		n = n // 2
	while n % 3 == 0:
		count = count + 2
		n = n // 3
	while n % 5 == 0:
		count = count + 3
		n = n // 5
	if n > 1:
		return -1
	return count

def main():
	q = int(input())
	for _ in range(q):
		s = int(input())
		print(sol(s))
main()


n = int(input())
for i in range(n):
	z = 0
	c = int(input())
	while c > 1 and (c % 2 == 0 or c % 3 == 0 or c % 5 == 0):
		if c % 2 == 0:
			z += 1
			c = c // 2
		if c % 3 == 0:
			z += 1
			c = 2 * c // 3
		if c % 5 == 0:
			c = 4 * c // 5
			z += 1
	if c == 1:
		print(z)
	else:
		print(-1)


for _ in range(int(input())):
	x = int(input())
	i = 0
	while x > 1:
		if not x % 2:
			x //= 2
		elif not x % 3:
			x *= 2
			x //= 3
		elif not x % 5:
			x *= 4
			x //= 5
		else:
			print('-1')
			break
		i += 1
	else:
		print(i)


q = int(input())
while q > 0:
	n = int(input())
	flag = 0
	count = 0
	while n > 1 and flag == 0:
		if n % 2 == 0:
			n = n // 2
			count = count + 1
		elif n % 3 == 0:
			n = n // 3
			count = count + 2
		elif n % 5 == 0:
			n = n // 5
			count = count + 3
		else:
			flag = 1
	if flag == 0 and n > 0:
		print(count)
	else:
		print(-1)
	q = q - 1


t = int(input())
for _ in range(t):
	n = int(input())
	c = 0
	while n != 1:
		if n % 2 == 0:
			n = n // 2
			c += 1
			continue
		if n % 3 == 0:
			n = n * 2 // 3
			c += 1
			continue
		if n % 5 == 0:
			n = 4 * n // 5
			c += 1
			continue
		if n % 2 != 0 or n % 3 != 0 or n % 5 != 0:
			c = -1
			break
	print(c)


t = int(input())
for _ in range(t):
	n = int(input())
	steps = 0
	while n != 1:
		steps += 1
		if n % 2 == 0:
			n //= 2
			continue
		if n % 3 == 0:
			n //= 3
			n *= 2
			continue
		if n % 5 == 0:
			n //= 5
			n *= 4
			continue
		break
	print(steps if n == 1 else -1)


t = int(input())
for _ in range(t):
	n = int(input())
	a = 0
	o = 1
	while n != 1:
		if n % 5 == 0:
			n = 4 * n // 5
		elif n % 3 == 0:
			n = 2 * n // 3
		elif n % 2 == 0:
			n = n // 2
		else:
			o = 0
			break
		a = a + 1
	if o:
		print(a)
	else:
		print('-1')


from sys import stdin, stdout
import math, sys, heapq
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import bisect as bi

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 = {}
	z = []
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
			z.append(x)
	return [d, z]

def find_gt(a, x):
	i = bi.bisect_right(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		n = I()
		ans = 0
		while n % 5 == 0:
			n = 4 * n
			n = n // 5
			ans += 1
		while n % 3 == 0:
			n = 2 * n
			n = n // 3
			ans += 1
		while n % 2 == 0:
			n = n // 2
			ans += 1
		if n == 1:
			print(ans)
		else:
			print(-1)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(I()):
	main()


Q = int(input())
array = []
count = [0] * Q
k = 0
for i in range(Q):
	array.append(int(input()))
for i in range(Q):
	x = array[i]
	while x != 1:
		k = x
		if x % 5 == 0:
			x = x * 4 // 5
			count[i] += 1
		if x % 3 == 0:
			x = x * 2 // 3
			count[i] += 1
		if x % 2 == 0:
			x = x // 2
			count[i] += 1
		if k == x:
			count[i] = -1
			break
for i in range(Q):
	print(count[i])


q = int(input())
cache = {}
cache[1] = 0
for _ in range(q):
	N = int(input())
	S = [N]
	while True:
		n = S[-1]
		if n in cache:
			break
		if n % 2 == 0:
			S.append(n // 2)
		elif n % 3 == 0:
			S.append(2 * n // 3)
		elif n % 5 == 0:
			S.append(4 * n // 5)
		else:
			cache[n] = -1
	for i in range(len(S) - 2, -1, -1):
		if cache[S[i + 1]] == -1:
			cache[S[i]] = -1
		else:
			cache[S[i]] = 1 + cache[S[i + 1]]
	print(cache[N])


t = int(input())
for i in range(t):
	n = int(input())
	if n == 1:
		print('0')
	else:
		x = n
		c = 0
		while x > 1:
			if x % 2 == 0:
				x = x // 2
				c = c + 1
			elif x % 3 == 0:
				x = x // 3
				c = c + 2
			elif x % 5 == 0:
				x = x // 5
				c = c + 3
			else:
				c = -1
				break
		print(c)


a = int(input())
home = []
cnt = 0
while True:
	b = int(input())
	cnt += 1
	home.append(b)
	if cnt == a:
		cnt = 0
		break
f = True
for i in home:
	while i != 1:
		if i % 2 == 0:
			cnt += 1
			i //= 2
		elif i % 3 == 0:
			cnt += 1
			i = i * 2 // 3
		elif i % 5 == 0:
			cnt += 1
			i = i * 4 // 5
		else:
			print(-1)
			f = False
			break
	if f:
		print(cnt)
	cnt = 0
	f = True


import sys

def get_pow(n, i):
	r = 0
	while n % i == 0:
		n = n // i
		r += 1
	return r

def solve(n):
	n2 = get_pow(n, 2)
	n3 = get_pow(n, 3)
	n5 = get_pow(n, 5)
	if 2 ** n2 * 3 ** n3 * 5 ** n5 != n:
		return -1
	return n5 + n3 + (n5 * 2 + n3 + n2)
sys.stdin.readline()
for line in sys.stdin:
	n = int(line)
	print(solve(n))


def LOL(aa):
	a = int(aa)
	n = 0
	if a > 1:
		while a % 2 == 0:
			a //= 2
			n += 1
		while a % 3 == 0:
			a //= 3
			n += 2
		while a % 5 == 0:
			a //= 5
			n += 3
	if a == 1:
		return n
	return -1
Q = []
W = int(input())
for i in range(W):
	Q.append(LOL(int(input())))
for q in Q:
	print(q)


a = int(input())
while a > 0:
	count = 0
	flag = 0
	q = int(input())
	while q != 1:
		if q % 5 == 0:
			count += 3
			q = q // 5
		elif q % 3 == 0:
			count += 2
			q = q // 3
		elif q % 2 == 0:
			count += 1
			q = q // 2
		else:
			print(-1)
			flag = 1
			break
	if flag != 1:
		print(count)
	a -= 1


N = int(input())
Ns = []
for n in range(N):
	Ns.append(int(input()))
for n in Ns:
	c = 0
	while n % 5 == 0:
		c += 3
		n = n // 5
	while n % 3 == 0:
		c += 2
		n = n // 3
	while n % 2 == 0:
		c += 1
		n = n // 2
	if n == 1:
		print(c)
	else:
		print(-1)


queries = int(input())
for i in range(queries):
	counter = 0
	cond = True
	number = int(input())
	if number == 1:
		print(0)
	else:
		while number != 1:
			if number % 2 == 0:
				number = number // 2
				counter += 1
			elif number % 3 == 0:
				number = 2 * (number // 3)
				counter += 1
			elif number % 5 == 0:
				number = 4 * (number // 5)
				counter += 1
			else:
				cond = False
				number = 1
				print(-1)
		if cond == True:
			print(counter)


def solve(n):
	result = 0
	while n % 2 == 0:
		n //= 2
		result += 1
	while n % 3 == 0:
		n //= 3
		result += 2
	while n % 5 == 0:
		n //= 5
		result += 3
	if n == 1:
		return result
	return -1
m = int(input())
a = []
for i in range(m):
	num = int(input())
	a.append(solve(num))
for i in a:
	print(i)


query = int(input())
for _ in range(query):
	n = int(input())
	count = 0
	p = True
	while n:
		if n == 1:
			break
		elif n < 1:
			p = False
			break
		elif not n % 5:
			n = 4 * (n // 5)
			count += 1
		elif not n % 3:
			n = 2 * (n // 3)
			count += 1
		elif not n % 2:
			n = n // 2
			count += 1
		else:
			p = False
			break
	if p:
		print(count)
	else:
		print(-1)


from sys import stdin, stdout
read = lambda : map(int, stdin.readline().split())
I = lambda : stdin.readline()
alias = {2: 1, 3: 2, 5: 3}
for i in range(int(I())):
	(n, count) = (int(I()), 0)
	for i in alias:
		while n % i == 0:
			count += alias[i]
			n //= i
	print(count if n == 1 else -1)


def func(n):
	(a, b, c) = (0, 0, 0)
	while n % 2 == 0:
		n //= 2
		a += 1
	while n % 3 == 0:
		n //= 3
		b += 1
	while n % 5 == 0:
		n //= 5
		c += 1
	if n == 1:
		return a + 2 * b + 3 * c
	return -1
q = int(input())
for _ in range(q):
	n = int(input())
	print(func(n))


def answer():
	element = int(input())
	counter = 0
	while element % 5 == 0:
		element //= 5
		element *= 4
		counter += 1
	while element % 3 == 0:
		element //= 3
		element *= 2
		counter += 1
	while element % 2 == 0:
		element //= 2
		counter += 1
	if element != 1:
		return -1
	return counter
r = int(input())
for i in range(r):
	print(answer())


n = int(input())
c = {'2': 1, '3': 2, '5': 3}
for i in range(n):
	k = int(input())
	turns = 0
	for d in [2, 3, 5]:
		while k % d == 0:
			k = k // d
			turns += c[str(d)]
	if k == 1:
		print(turns)
	else:
		print(-1)


def test(test_case):
	if test_case == 1:
		return 0
	if test_case % 2 == 0:
		temp = test(test_case // 2)
		if temp != -1:
			return temp + 1
		return -1
	if test_case % 3 == 0:
		temp = test(test_case * 2 // 3)
		if temp != -1:
			return temp + 1
		return -1
	if test_case % 5 == 0:
		temp = test(test_case * 4 // 5)
		if temp != -1:
			return temp + 1
		return -1
	return -1
q_count = int(input())
for _ in range(q_count):
	print(test(int(input())))


q = int(input())
for i in range(q):
	n = int(input())
	ans = 0
	flag = False
	while n != 1:
		if n % 2 == 0:
			n //= 2
			ans += 1
		else:
			break
	while n != 1:
		if n % 3 == 0:
			n //= 3
			ans += 2
		else:
			break
	while n != 1:
		if n % 5 == 0:
			n //= 5
			ans += 3
		else:
			break
	if n != 1:
		print(-1)
	else:
		print(ans)


n = int(input())
for _ in range(n):
	co = 0
	k = 0
	np = int(input())
	while np != 1:
		if np % 2 == 0:
			co += 1
			np //= 2
		elif np % 3 == 0:
			co += 1
			np = 2 * np // 3
		elif np % 5 == 0:
			co += 1
			np = 4 * np // 5
		else:
			print(-1)
			k = 1
			break
	if k == 0:
		print(co)


from math import log2

def divide(n):
	(moves_3, moves_5) = (0, 0)
	while n % 3 == 0:
		n //= 3
		moves_3 += 1
	while n % 5 == 0:
		n //= 5
		moves_5 += 1
	t = int(log2(n))
	if 2 ** t != n:
		return -1
	return t + moves_3 * 2 + moves_5 * 3

def main():
	q = int(input())
	results = [''] * q
	for i in range(q):
		results[i] = str(divide(int(input())))
	print('\n'.join(results))
main()


def helper(n):
	res = 0
	while n % 5 == 0:
		n //= 5
		res += 3
	while n % 3 == 0:
		n //= 3
		res += 2
	while n % 2 == 0:
		n >>= 1
		res += 1
	if n == 1:
		print(res)
	else:
		print(-1)
q = int(input())
for _ in range(q):
	num = int(input())
	helper(num)


def fun(n):
	ans = 0
	while n % 2 == 0:
		n = n // 2
		ans += 1
	while n % 3 == 0:
		n = n // 3
		ans += 2
	while n % 5 == 0:
		n = n // 5
		ans += 3
	if n == 1:
		return ans
	return -1
q = int(input())
while q:
	q -= 1
	n = int(input())
	print(fun(n))


import sys
n = 0
b = 0
for line in sys.stdin:
	if n == 0:
		n = int(line.strip())
	else:
		b += 1
		a = int(line.strip())
		counter = 0
		while a % 2 == 0 and a != 1:
			a = a // 2
			counter += 1
		while a % 3 == 0 and a != 1:
			a = a // 3
			counter += 2
		while a % 5 == 0 and a != 1:
			a = a // 5
			counter += 3
		if a != 1:
			print(-1)
		else:
			print(counter)
	if n == b:
		sys.exit()


import math
q = int(input())
for i in range(q):
	n = int(input())
	count2 = 0
	while n % 2 == 0:
		count2 += 1
		n = n // 2
	count3 = 0
	while n % 3 == 0:
		count3 += 1
		n = n // 3
	count5 = 0
	while n % 5 == 0:
		count5 += 1
		n = n // 5
	if n != 1:
		print(-1)
	else:
		print(count2 + 2 * count3 + 3 * count5)


def degree(n, p):
	cnt = 0
	while n % p == 0:
		n //= p
		cnt += 1
	return cnt
for i in range(int(input())):
	n = int(input())
	(a2, a3, a5) = [degree(n, p) for p in [2, 3, 5]]
	if n // (2 ** a2 * 3 ** a3 * 5 ** a5) != 1:
		print(-1)
	else:
		print(a2 + 2 * a3 + 3 * a5)


from math import *
from itertools import *
from collections import *
from bisect import *
q = int(input())
for _ in range(q):
	n = int(input())
	result = 0
	while n > 1:
		if n % 5 == 0:
			n = n * 4 // 5
		elif n % 3 == 0:
			n = n * 2 // 3
		elif n % 2 == 0:
			n = n // 2
		else:
			result = -1
			break
		result += 1
	print(result)


t = int(input())
for _ in range(t):
	n = int(input())
	c = 0
	flag = 0
	while 1:
		if n % 2 == 0:
			n = n // 2
			c += 1
		if n % 3 == 0:
			n = 2 * n // 3
			c += 1
		if n % 5 == 0:
			n = 4 * n // 5
			c += 1
		if n == 1:
			break
		if n % 5 != 0 and n % 3 != 0 and (n % 2 != 0):
			print('-1')
			flag = 1
			break
	if flag == 0:
		print(c)


q = int(input())
answers = []
for i in range(q):
	n = int(input())
	steps = 0
	while n != 1:
		if n % 2 == 0:
			n //= 2
			steps += 1
		elif n % 3 == 0:
			n = n // 3
			steps += 2
		elif n % 5 == 0:
			n = n // 5
			steps += 3
		else:
			answers.append('-1')
			break
	else:
		answers.append(str(steps))
print('\n'.join(answers))


def solve(x):
	c = 0
	while x != 1:
		if x % 2 == 0:
			c += 1
			x = x // 2
		elif x % 3 == 0:
			c += 1
			x = 2 * x // 3
		elif x % 5 == 0:
			c += 1
			x = 4 * x // 5
		else:
			return -1
	return c
q = int(input())
for x in range(q):
	n = int(input())
	print(solve(n))


def main():
	t = int(input())
	for _ in range(t):
		num = int(input())
		cnt = 0
		flag = True
		while num > 1:
			if num % 5 == 0:
				num = num // 5
				cnt = cnt + 3
			elif num % 3 == 0:
				num = num // 3
				cnt = cnt + 2
			elif num % 2 == 0:
				num = num // 2
				cnt = cnt + 1
			else:
				flag = False
				break
		print(cnt if flag else -1)
main()


def f():
	n = int(input())
	c = 0
	while not n % 2:
		c += 1
		n //= 2
	while not n % 3:
		c += 2
		n //= 3
	while not n % 5:
		c += 3
		n //= 5
	print(c if n == 1 else -1)
for i in range(int(input())):
	f()


import math
n = int(input())
while n > 0:
	n -= 1
	m = int(input())
	c = 0
	while m % 5 == 0:
		c += 1
		m = 4 * m // 5
	while m % 3 == 0:
		c += 1
		m = 2 * m // 3
	while m % 2 == 0:
		c += 1
		m = m // 2
	if m == 1:
		print(c)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	cnt = 0
	l = []
	while True:
		if n in l:
			print(-1)
			break
		else:
			l.append(n)
		if n % 2 == 0:
			n //= 2
			cnt += 1
		if n * 2 % 3 == 0:
			n = 2 * n // 3
			cnt += 1
		if 4 * n % 5 == 0:
			n = 4 * n // 5
			cnt += 1
		if n == 1:
			print(cnt)
			break


def divide(q, inp):
	for item in inp:
		count = 0
		if item == 1:
			print(count)
		else:
			while item != 1:
				if item % 2 == 0:
					item = item // 2
				elif item % 3 == 0:
					item = 2 * item // 3
				elif item % 5 == 0:
					item = 4 * item // 5
				else:
					count = -1
					break
				count += 1
			print(count)
q = int(input())
inp = []
for i in range(q):
	aux = int(input())
	inp.append(aux)
divide(q, inp)


def divide(n):
	c = 0
	if n == 1:
		return 0
	else:
		while n >= 1:
			if n % 2 == 0 and n // 2 < n:
				n = n // 2
			elif n % 3 == 0 and 2 * n // 3 < n:
				n = 2 * n // 3
			elif n % 5 == 0 and 4 * n // 5 < n:
				n = 4 * n // 5
			else:
				break
			c += 1
		if n != 1:
			return -1
		return c
tc = int(input())
for i in range(tc):
	n = int(input())
	print(divide(n))


import sys
from collections import Counter

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

def dinput():
	return int(input())

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

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

def main():
	t = int(input())
	a = 0
	while t % 5 == 0:
		t = 4 * t // 5
		a += 1
	while t % 3 == 0:
		t = 2 * t // 3
		a += 1
	while t % 2 == 0:
		t //= 2
		a += 1
	if t != 1:
		print(-1)
	else:
		print(a)
for i in range(int(input())):
	main()


n = int(input())
for i in range(n):
	l = int(input())
	f = 0
	pop = 0
	while l != 1 and f == 0:
		if l % 2 == 0:
			pop += 1
			l //= 2
		elif l % 3 == 0:
			pop += 1
			l //= 3
			l *= 2
		elif l % 5 == 0:
			pop += 1
			l //= 5
			l *= 4
		else:
			f = 1
			pop = -1
	print(pop)


q = int(input())
i = 1
while i <= q:
	n = int(input())
	temp1 = 0
	temp2 = 0
	temp3 = 0
	moves = 0
	c = 0
	while n != 1:
		if n % 2 == 0:
			n = n // 2
		elif n % 3 == 0:
			temp2 = 2 * n
			n = temp2 // 3
		elif n % 5 == 0:
			temp3 = 4 * n
			n = temp3 // 5
		else:
			print(-1)
			c = 1
			break
		moves += 1
	if c == 0:
		print(moves)
	i += 1


k = int(input())
for q in range(k):
	n = int(input())
	q1 = 0
	while n % 5 == 0:
		n = n // 5 * 4
		q1 += 1
	while n % 3 == 0:
		n = n // 3 * 2
		q1 += 1
	while n % 2 == 0:
		n //= 2
		q1 += 1
	if n == 1:
		print(q1)
	else:
		print(-1)


def nu(n):
	co = 0
	while n != 1:
		if n % 2 == 0:
			n = n // 2
			co += 1
		elif n % 3 == 0:
			n = n // 3
			co += 2
		elif n % 5 == 0:
			n = n // 5
			co += 3
		else:
			return -1
	return co
n = int(input())
for _ in range(n):
	print(nu(int(input())))


for _ in range(int(input())):
	n = int(input())
	flag = 1
	c = 0
	if n is 1:
		print(0)
		continue
	while n % 2 is 0 or n % 3 is 0 or n % 5 is 0:
		if n % 2 is 0:
			n = n // 2
			c += 1
		elif n % 3 is 0:
			n = 2 * n // 3
			c += 1
		elif n % 5 is 0:
			n = 4 * n // 5
			c += 1
		if n is 1:
			print(c)
			flag = 0
			break
	if flag:
		print(-1)


def function(n):
	x = n
	counter = 0
	while x != 1:
		if x % 5 == 0:
			x = x // 5 * 4
		elif x % 3 == 0:
			x = x // 3 * 2
		elif x % 2 == 0:
			x = x // 2
		else:
			return -1
		counter += 1
	return counter
N = int(input())
for i in range(N):
	print(function(int(input())))


a = int(input())
for i in range(a):
	n = int(input())
	for j in range(10 * 18):
		if n == 1:
			break
		if n % 2 == 0:
			n = n // 2
		elif n % 3 == 0:
			n = 2 * n // 3
		elif n % 5 == 0:
			n = 4 * n // 5
	print(j if n == 1 else -1)


for i in range(int(input())):
	a = int(input())
	c = 0
	while a % 5 == 0:
		c += 3
		a = a // 5
	while a % 3 == 0:
		c += 2
		a = a // 3
	while a % 2 == 0:
		c += 1
		a = a // 2
	print(c if a == 1 else -1)


for _ in range(int(input())):
	n = int(input())
	ret = 0
	while n > 1 and n % 2 == 0:
		n //= 2
		ret += 1
	while n > 1 and n % 3 == 0:
		n //= 3
		ret += 2
	while n > 1 and n % 5 == 0:
		n = n // 5
		ret += 3
	print(ret if n == 1 else -1)


from math import *
from cmath import *
from itertools import *
from decimal import *
from fractions import *
from sys import *
for _ in range(int(input())):
	n = int(input())
	ans = 0
	while n > 1 and n % 2 == 0:
		ans += 1
		n //= 2
	while n > 1 and n % 3 == 0:
		ans += 2
		n //= 3
	while n > 1 and n % 5 == 0:
		ans += 3
		n //= 5
	print([ans, -1][n > 1])


n = int(input())
for _ in range(n):
	inp = int(input())
	if inp == 1:
		print('0')
	else:
		j = inp
		count = 0
		while j != 1:
			if j % 2 == 0:
				j = j // 2
				count += 1
			elif j % 3 == 0:
				j = 2 * j // 3
				count += 1
			elif j % 5 == 0:
				j = 4 * j // 5
				count += 1
			else:
				count = -1
				break
		print(count)


def f(n):
	if n == 1:
		return 0
	if not n % 5:
		return f(4 * n // 5) + 1
	elif not n % 3:
		return f(2 * n // 3) + 1
	elif not n % 2:
		return f(n // 2) + 1
	else:
		return -1000
n = int(input())
for i in range(n):
	a = int(input())
	b = f(a)
	if b >= 0:
		print(b)
	else:
		print(-1)


test_cases = int(input())

def is_divisible(num, divisor):
	return num % divisor == 0

def can_divide(num):
	return any([is_divisible(num, 2), is_divisible(num, 3), is_divisible(num, 5)])

def splits(num):
	if num % 2 == 0:
		return num // 2
	if num % 3 == 0:
		return num * 2 // 3
	if num % 5 == 0:
		return num * 4 // 5

def no_of_divisions(num):
	divisions = 0
	while num != 1:
		if can_divide(num):
			num = splits(num)
			divisions += 1
		else:
			return -1
	return divisions
for i in range(test_cases):
	num = int(input())
	if num <= 1:
		print(0)
	else:
		print(no_of_divisions(num))


for i in range(int(input())):
	l = int(input())
	(s, j) = (0, 0)
	s = l
	while True:
		if s == 1:
			print(j)
			break
		elif s % 2 == 0:
			s = s // 2
			j += 1
		elif s % 3 == 0:
			s = 2 * s // 3
			j += 1
		elif s % 5 == 0:
			s = 4 * s // 5
			j += 1
		else:
			print(-1)
			break


import os
import sys
import string
import math

def solution(num):
	m2 = 0
	m3 = 0
	m5 = 0
	while num != 1:
		if num % 5 == 0:
			num = num // 5
			m5 += 1
		elif num % 3 == 0:
			num = num // 3
			m3 += 1
		elif num % 2 == 0:
			num = num // 2
			m2 += 1
		else:
			return -1
	return m2 + 2 * m3 + 3 * m5

def main(nums):
	for num in nums:
		print(solution(num))

def parse():
	n = int(input())
	nums = []
	for _ in range(n):
		nums.append(int(input()))
	return nums
main(parse())


from math import log
t = int(input())
while t > 0:
	n = int(input())
	if n == 1:
		print(0)
	else:
		count = 0
		while n != 1:
			if n & n - 1 == 0:
				count += log(n, 2)
				break
			elif n % 5 == 0:
				n = 4 * n // 5
				count += 1
			elif n % 3 == 0:
				n = 2 * n // 3
				count += 1
			elif n % 2 == 0:
				n = n // 2
				count += 1
			else:
				count = -1
				break
		print(int(count))
	t -= 1


import math
MOD = 1000000007
t = int(input())
while t:
	t -= 1
	n = int(input())
	if n == 1:
		print(0)
		continue
	five = 0
	two = 0
	three = 0
	while n % 5 == 0:
		five += 1
		n //= 5
	while n % 3 == 0:
		three += 1
		n //= 3
	while n % 2 == 0:
		two += 1
		n //= 2
	if n != 1:
		print(-1)
		continue
	print(five * 3 + three * 2 + two)


from decimal import *
n = int(input())
inputs = [int(input()) for x in range(0, n)]
d = Decimal

def nosfor1(n):
	if n < 1:
		return -1
	steps = 0
	while n > 1:
		if n % 2 == 0:
			steps = steps + 1
			n = n / 2
		elif n % 3 == 0:
			steps = steps + 1
			n = 2 * n / 3
		elif n % 5 == 0:
			steps = steps + 1
			n = 4 * n / 5
		else:
			return -1
	return steps
for ip in inputs:
	print(nosfor1(d(ip)))


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	ans = 0
	while n != 1:
		if n % 2 == 0:
			n //= 2
			ans += 1
		elif n % 3 == 0:
			n //= 3
			ans += 2
		elif n % 5 == 0:
			n //= 5
			ans += 3
		else:
			break
	if n == 1:
		print(ans)
	else:
		print(-1)


n = int(input())
for i in range(n):
	x = int(input())
	contador = 0
	ff = True
	while x != 1:
		flag = False
		if x % 2 == 0:
			x = x // 2
			flag = True
			contador += 1
			continue
		if x % 3 == 0:
			x = 2 * x // 3
			flag = True
			contador += 1
			continue
		if x % 5 == 0:
			x = 4 * x // 5
			flag = True
			contador += 1
			continue
		if not flag:
			print(-1)
			ff = False
			break
	if ff:
		print(contador)


q = int(input())
for i in range(q):
	n = int(input())
	for j in range(n):
		if n % 2 == 0:
			n = n // 2
		elif n % 3 == 0:
			n = n // 3 * 2
		elif n % 5 == 0:
			n = n // 5 * 4
		else:
			break
	if n == 1:
		print(int(j))
	else:
		print(-1)


from math import *
a = int(input())
for i in range(a):
	z = int(input())
	k = 0
	if z == 1:
		print(0)
	else:
		while True:
			if z % 2 == 0:
				z = z // 2
				k += 1
			elif z % 3 == 0:
				z = 2 * z // 3
				k += 1
			elif z % 5 == 0:
				z = 4 * z // 5
				k += 1
			else:
				if z == 1:
					print(k)
				else:
					print(-1)
				break


def read(t=int):
	return list(map(t, input().strip().split(' ')))
t = read()[0]
while t:
	t -= 1
	n = read()[0]
	c = 0
	while n % 5 == 0:
		n = n // 5
		c += 3
	while n % 3 == 0:
		n = n // 3
		c += 2
	while n % 2 == 0:
		n = n // 2
		c += 1
	if n == 1:
		print(c)
	else:
		print(-1)


class cinn:

	def __init__(self):
		self.x = []

	def cin(self, t=int):
		if len(self.x) == 0:
			a = input()
			self.x = a.split()
			self.x.reverse()
		return self.get(t)

	def get(self, t):
		return t(self.x.pop())

	def clist(self, n, t=int):
		l = [0] * n
		for i in range(n):
			l[i] = self.cin(t)
		return l

	def clist2(self, n, t1=int, t2=int, t3=int, tn=2):
		l = [0] * n
		for i in range(n):
			if tn == 2:
				a1 = self.cin(t1)
				a2 = self.cin(t2)
				l[i] = (a1, a2)
			elif tn == 3:
				a1 = self.cin(t1)
				a2 = self.cin(t2)
				a3 = self.cin(t3)
				l[i] = (a1, a2, a3)
		return l

	def clist3(self, n, t1=int, t2=int, t3=int):
		return self.clist2(self, n, t1, t2, t3, 3)

	def cout(self, i, ans=''):
		if ans == '':
			print('Case #' + str(i + 1) + ':', end=' ')
		else:
			print('Case #' + str(i + 1) + ':', ans)

	def printf(self, thing):
		print(thing, end='')

	def countlist(self, l, s=0, e=None):
		if e == None:
			e = len(l)
		dic = {}
		for el in range(s, e):
			if l[el] not in dic:
				dic[l[el]] = 1
			else:
				dic[l[el]] += 1
		return dic

	def talk(self, x):
		print(x, flush=True)

	def dp1(self, k):
		L = [-1] * k
		return L

	def dp2(self, k, kk):
		L = [-1] * k
		for i in range(k):
			L[i] = [-1] * kk
		return L
c = cinn()
n = c.cin()
for i in range(n):
	q = c.cin()
	totop = 0
	while q != 1:
		if q % 2 == 0:
			q = q // 2
			totop += 1
		elif q % 3 == 0:
			q = 2 * q // 3
			totop += 1
		elif q % 5 == 0:
			q = 4 * q // 5
			totop += 1
		else:
			totop = -1
			break
	print(totop)


q = int(input())
for query in range(q):
	n = int(input())
	count = 0
	while n % 2 == 0:
		n = n // 2
		count += 1
	while n % 3 == 0:
		n = n // 3
		count += 2
	while n % 5 == 0:
		n = n // 5
		count += 3
	if n == 1:
		print(count)
	else:
		print(-1)


def f(n):
	if n == 1:
		return 0
	if n % 2 == 0:
		return 1 + f(n // 2)
	if n % 3 == 0:
		return 1 + f(2 * n // 3)
	if n % 5 == 0:
		return 1 + f(4 * n // 5)
	return float('inf')
q = int(input())
for _ in range(q):
	n = int(input())
	x = f(n)
	if x > 10 ** 18:
		print(-1)
		continue
	print(x)


T = int(input())
testcase = 0
while testcase < T:
	n = int(input())
	res = -1
	time = 0
	while n > 1:
		if n % 2 == 0:
			n = n // 2
		elif n % 3 == 0:
			n = n - n // 3
		elif n % 5 == 0:
			n = n - n // 5
		else:
			break
		time += 1
	if n == 1:
		print(time)
	else:
		print(-1)
	testcase += 1


t = int(input())
k = []
for i in range(t):
	n = int(input())
	ans = 0
	while n != 1:
		if n == 1:
			break
		if n % 2 == 0:
			n = n // 2
		elif n % 3 == 0:
			n = 2 * n // 3
		elif n % 5 == 0:
			n = 4 * n // 5
		else:
			ans = -1
			break
		ans += 1
	k.append(ans)
for i in k:
	print(i)


queries = int(input())
for i in range(queries):
	counter = 0
	n = int(input())
	if n == 1:
		print(0)
		continue
	while int(list(str(n))[-1]) in range(0, 9, 2):
		n //= 2
		counter += 1
	while int(list(str(n))[-1]) == (0 or 5):
		n //= 5
		counter += 3
	while sum(list(map(int, str(n)))) % 3 == 0:
		n //= 3
		counter += 2
	if n == 1:
		print(counter)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	prev = -1
	count = 0
	flag = True
	while n != 1:
		if prev == count:
			print(-1)
			flag = False
			break
		if n % 2 == 0:
			n = n // 2
			count += 1
			continue
		elif n % 3 == 0:
			n = 2 * n // 3
			count += 1
			continue
		elif n % 5 == 0:
			n = 4 * n // 5
			count += 1
			continue
		prev = count
	if flag:
		print(count)


t = int(input())
while t != 0:
	(cnt2, cnt3, cnt5) = (0, 0, 0)
	t -= 1
	n = int(input())
	while n % 3 == 0:
		n = n // 3
		n = n * 2
		cnt3 += 1
	while n % 5 == 0:
		n = n // 5
		n = n * 4
		cnt5 += 1
	while n % 2 == 0:
		n = n // 2
		cnt2 += 1
	if n != 1:
		print('-1')
	else:
		print(cnt2 + cnt3 + cnt5)


def main():
	q = int(input())
	for i in range(q):
		t = int(input())
		ans = 0
		while t % 5 == 0:
			t = 4 * t // 5
			ans += 1
		while t % 3 == 0:
			t = 2 * t // 3
			ans += 1
		while t % 2 == 0:
			t //= 2
			ans += 1
		if t != 1:
			print(-1)
		else:
			print(ans)
main()


from fractions import gcd
from itertools import combinations, permutations, accumulate, product
from collections import deque, defaultdict, Counter
import decimal
import re
import math
import bisect
import sys
sys.setrecursionlimit(10000000)
mod = 10 ** 9 + 7
from sys import stdin
readline = stdin.readline

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

def readTuples():
	return tuple(map(int, readline().split()))

def I():
	return int(readline())
for _ in range(I()):
	n = I()
	ans = 0
	flag = True
	while n != 1:
		if n % 2 == 0:
			n //= 2
			ans += 1
			continue
		if n % 3 == 0:
			n //= 3
			n *= 2
			ans += 1
			continue
		if n % 5 == 0:
			n //= 5
			n *= 4
			ans += 1
			continue
		print(-1)
		flag = False
		break
	if flag:
		print(ans)


def main():
	k = int(input())
	for i in range(k):
		n = int(input())
		sum = 0
		while n % 5 == 0:
			n = 4 * n // 5
			sum += 1
		while n % 3 == 0:
			n = 2 * n // 3
			sum += 1
		while n % 2 == 0:
			n = n // 2
			sum += 1
		if n == 1:
			print(sum)
		else:
			print(-1)
main()


from sys import stdin, stdout
input = stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	c = 0
	flg = 0
	while 1:
		if n == 1:
			break
		if n % 2 == 0:
			n //= 2
			c += 1
		elif n % 3 == 0:
			n *= 2
			n //= 3
			c += 1
		elif n % 5 == 0:
			n *= 4
			n //= 5
			c += 1
		else:
			flg = 1
			break
	if flg:
		print(-1)
	else:
		print(c)


q = int(input())
for ir in range(q):
	n = int(input())
	if n == 1:
		print(0)
		continue
	ans = 0
	while 1:
		if n % 2 != 0 and n % 3 != 0 and (n % 5 != 0):
			break
		if n % 2 == 0:
			n = n // 2
			ans += 1
		if n % 5 == 0:
			n = 4 * n // 5
			ans += 1
		if n % 3 == 0:
			n = 2 * n // 3
			ans += 1
	if n != 1:
		print(-1)
		continue
	print(ans)


for q in range(int(input())):
	(n, v) = (int(input()), 0)
	while n % 2 == 0:
		(n, v) = (n // 2, v + 1)
	while n % 3 == 0:
		(n, v) = (n // 3, v + 2)
	while n % 5 == 0:
		(n, v) = (n // 5, v + 3)
	print(v if n == 1 else -1)


def chk(n):
	if n % 2 == 0 or n % 3 == 0 or n % 5 == 0:
		return 1
	return 0
for _ in range(int(input())):
	n = int(input())
	cnt = 0
	f = 0
	while n != 1:
		if chk(n):
			if n % 5 == 0:
				n = 4 * n // 5
			elif n % 3 == 0:
				n = 2 * n // 3
			else:
				n = n // 2
			cnt += 1
		else:
			print(-1)
			f = 1
			break
	if not f:
		print(cnt)


import sys
import os
from io import IOBase, BytesIO

def main():
	for tc in range(int(input())):
		n = int(input())
		ans = 0
		flag = True
		while n != 1:
			if n % 2 == 0:
				n //= 2
			elif n % 3 == 0:
				n //= 3
				n *= 2
			elif n % 5 == 0:
				n //= 5
				n *= 4
			else:
				flag = False
				break
			ans += 1
		if flag == True:
			print(ans)
		else:
			print(-1)
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):
		py2 = round(0.5)
		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))

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

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

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


def howmany(k, ans):
	if k == 1:
		return ans
	elif ans == -1:
		return -1
	elif k % 2 == 0:
		return howmany(k // 2, ans + 1)
	elif k % 3 == 0:
		return howmany(k // 3, ans + 2)
	elif k % 5 == 0:
		return howmany(k // 5, ans + 3)
	else:
		return -1
n = int(input())
for i in range(n):
	k = int(input())
	print(howmany(k, 0))


from sys import stdin

def solve(tc):
	nq = int(stdin.readline().strip())
	for _ in range(nq):
		q = int(stdin.readline().strip())
		cnt = 0
		while q > 1:
			if q % 2 == 0:
				q //= 2
			elif q % 3 == 0:
				q = q // 3 * 2
			elif q % 5 == 0:
				q = q // 5 * 4
			elif q > 1:
				cnt = -1
				break
			cnt += 1
		print(cnt)
LOCAL_TEST = not __debug__
if LOCAL_TEST:
	infile = __file__.split('.')[0] + '-test.in'
	stdin = open(infile, 'r')
tcs = int(stdin.readline().strip()) if LOCAL_TEST else 1
tc = 1
while tc <= tcs:
	solve(tc)
	tc += 1


n = int(input())
res = [None for i in range(n)]
for i in range(n):
	local = int(input())
	k = 0
	if local == 1:
		res[i] = 0
	else:
		while local != 1:
			k += 1
			if local % 2 == 0:
				local //= 2
			elif local % 3 == 0:
				local = 2 * local // 3
			elif local % 5 == 0:
				local = 4 * local // 5
			else:
				res[i] = -1
				break
		if res[i] == None:
			res[i] = k
for i in range(n):
	print(res[i])


import sys
import math
input = sys.stdin.readline
sys.setrecursionlimit(100000)

def getN():
	return int(input())

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

def solve():
	num = getN()
	ans = 0
	while True:
		if num % 2 == 0:
			num = num // 2
		elif num % 3 == 0:
			num = num // 3 * 2
		elif num % 5 == 0:
			num = num // 5 * 4
		elif num == 1:
			print(ans)
			return
		else:
			print(-1)
			return
		ans += 1
n = getN()
for i in range(n):
	solve()


n = int(input())
while n != 0:
	num = int(input())
	flag = 0
	five = 0
	two = 0
	three = 0
	number = num
	while num != 1:
		if num % 5 == 0:
			num = num // 5
			five += 1
			continue
		elif num % 3 == 0:
			num = num // 3
			three += 1
			continue
		elif num % 2 == 0:
			num = num // 2
			two += 1
			continue
		else:
			print(-1)
			flag = 1
			break
	if flag == 0 and number == 5 ** five * 3 ** three * 2 ** two:
		print(two + three * 2 + five * 3)
	elif flag == 0:
		print(-1)
	n -= 1


T = int(input())
for t in range(T):
	counter = 0
	k = int(input())
	while k % 2 == 0:
		k = k // 2
		counter = counter + 1
	while k % 3 == 0:
		k = k // 3
		counter = counter + 2
	while k % 5 == 0:
		k = k // 5
		counter = counter + 3
	if k != 1:
		print('-1')
	else:
		print(counter)


def ysfj(a, x):
	j = 0
	while a % x == 0:
		j = j + 1
		a = a // x
	return [a, j]

def di(a):
	j = []
	for t in [2, 3, 5]:
		j.append(ysfj(a, t)[1])
		a = ysfj(a, t)[0]
	if int(a) == 1:
		return int(j[0] + 2 * j[1] + 3 * j[2])
	else:
		return -1

def main():
	n = int(input())
	for i in range(n):
		a = int(input())
		print(di(a))
main()


n = int(input())
a = [0] * n
ans = [0] * n
for i in range(n):
	a[i] = int(input())
for i in range(n):
	while a[i] % 3 == 0:
		a[i] //= 3
		ans[i] += 2
	while a[i] % 5 == 0:
		a[i] //= 5
		ans[i] += 3
	while a[i] % 2 == 0:
		a[i] //= 2
		ans[i] += 1
	if a[i] != 1:
		ans[i] = -1
for i in range(n):
	print(ans[i])


def div(n, d):
	return True if n % d is 0 else False
for _ in range(int(input())):
	n = int(input())
	ans = 0
	while n != 1:
		if div(n, 5):
			n = n * 4 // 5
		elif div(n, 3):
			n = n * 2 // 3
		elif div(n, 2):
			n = n // 2
		else:
			break
		ans += 1
	print(ans if n == 1 else -1)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	k = n
	count2 = 0
	count3 = 0
	count5 = 0
	while n % 3 == 0:
		count3 += 1
		n = n // 3
	while n % 5 == 0:
		count5 += 1
		n = n // 5
	while n % 2 == 0:
		count2 += 1
		n = n // 2
	if n == 1:
		for i in range(count5):
			k = 4 * k // 5
		for i in range(count3):
			k = 2 * k // 3
		print(count3 + count5 + int(math.log(k, 2)))
	else:
		print('-1')


def main():
	numbers = int(input())
	for i in range(numbers):
		result = 0
		query = int(input())
		if query == 1:
			pass
		else:
			while query != 1:
				if query % 2 == 0:
					while query % 2 == 0:
						query = query // 2
						result = result + 1
				elif query % 3 == 0:
					while query % 3 == 0:
						query = query * 2 // 3
						result = result + 1
				elif query % 5 == 0:
					while query % 5 == 0:
						query = query * 4 // 5
						result = result + 1
				else:
					result = -1
					break
		print(result)
main()


from sys import stdin, stdout

def fn(n):
	if n == 1:
		return 0
	if n % 2 == 0:
		return 1 + fn(n // 2)
	if n % 3 == 0:
		return 1 + fn(2 * n // 3)
	if n % 5 == 0:
		return 1 + fn(4 * n // 5)
	return float('inf')
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	ans = fn(n)
	print(ans if ans != float('inf') else -1)


import sys, math

def read_int():
	return int(sys.stdin.readline().strip())

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

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

def read_string_list(delim=' '):
	return sys.stdin.readline().strip().split(delim)

def print_int_list(l):
	print(' '.join(map(str, l)))

def err_print(*args, **kwargs):
	print(*args, file=sys.stderr, **kwargs)
q = read_int()
for _ in range(q):
	n = read_int()
	out = 0
	while n != 1:
		if n % 2 == 0:
			n = n // 2
			out += 1
		elif n % 3 == 0:
			n = 2 * n // 3
			out += 1
		elif n % 5 == 0:
			n = 4 * n // 5
			out += 1
		else:
			break
	if n == 1:
		print(out)
	else:
		print(-1)


nk = int(input())
count = 0
ans = []
for i in range(nk):
	n = int(input())
	while n != 1:
		if n % 2 == 0:
			n = n // 2
			count += 1
		elif n % 3 == 0:
			n = 2 * n // 3
			count += 1
		elif n % 5 == 0:
			n = 4 * n // 5
			count += 1
		else:
			n = 1
			count = -1
	ans.append(count)
	count = 0
for j in ans:
	print(j)


t = int(input())
for case in range(t):
	n = int(input())
	cnt = 0
	while n % 5 == 0:
		n = n // 5
		cnt += 3
	while n % 3 == 0:
		n = n // 3
		cnt += 2
	while n % 2 == 0:
		n = n // 2
		cnt += 1
	if n == 1:
		print(cnt)
	else:
		print(-1)


import math
import bisect
import heapq
from collections import defaultdict

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		(g, x, y) = egcd(b % a, a)
		return (g, y - b // a * x, x)

def mulinv(b, n):
	(g, x, _) = egcd(b, n)
	if g == 1:
		return x % n

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

def argsort(ls):
	return sorted(range(len(ls)), key=ls.__getitem__)

def f(p=0):
	if p == 1:
		return map(int, input().split())
	elif p == 2:
		return list(map(int, input().split()))
	elif p == 3:
		return list(input())
	else:
		return int(input())

class DisjointSet:
	_disjoint_set = list()

	def __init__(self, init_arr):
		self._disjoint_set = []
		if init_arr:
			for item in list(set(init_arr)):
				self._disjoint_set.append([item])

	def _find_index(self, elem):
		for item in self._disjoint_set:
			if elem in item:
				return self._disjoint_set.index(item)
		return None

	def find(self, elem):
		for item in self._disjoint_set:
			if elem in item:
				return self._disjoint_set[self._disjoint_set.index(item)]
		return None

	def union(self, elem1, elem2):
		index_elem1 = self._find_index(elem1)
		index_elem2 = self._find_index(elem2)
		if index_elem1 != index_elem2 and index_elem1 is not None and (index_elem2 is not None):
			self._disjoint_set[index_elem2] = self._disjoint_set[index_elem2] + self._disjoint_set[index_elem1]
			del self._disjoint_set[index_elem1]
		return self._disjoint_set

	def get(self):
		return self._disjoint_set

def graph(n, m, edg=False):
	edges = []
	visited = [0] * n
	g = [list() for _ in range(n + 1)]
	for i in range(m):
		(u, v) = f(1)
		g[u].append(v)
		g[v].append(u)
		if edg:
			edges.append((u, v))
	if edg:
		return (g, visited, edg)
	else:
		return (g, visited)

def bfs(g, visited):
	queue = [1]
	visited[1] = 1
	for u in queue:
		for v in g[u]:
			if visited[v] == 0:
				queue.append(v)
			visited[v] = 1

def dfs(u, g, visited):
	print(u)
	visited[u] = 1
	for v in g[u]:
		if visited[v] == 0:
			dfs(v, g, visited)
t = int(input())
for i in range(t):
	n = int(input())
	k = 0
	a = 0
	b = 0
	c = 0
	while n % 2 == 0:
		n = n // 2
		a += 1
	while n % 3 == 0:
		n = n // 3
		k += 1
		b += 1
	while n % 5 == 0:
		n = n // 5
		k += 2
		c += 1
	if n == 1:
		print(a + b + c + k)
	else:
		print(-1)