# 题解 CF1374B 【Multiply by 2, divide by 6】

### 代码

// #include <iostream>
// #include <cstdio>
// #include <algorithm>
// #include <cstring>
// #include <vector>
#include <bits/stdc++.h>
#define maxn 100001
#define ls x << 1
#define rs x << 1 | 1
#define inf 0x3f3f3f3f
#define inc(i) (++ (i))
#define dec(i) (-- (i))
#define mid ((l + r) >> 1)
// #define int long long
#define XRZ 1000000003
#define debug() puts("XRZ TXDY");
#define mem(i, x) memset(i, x, sizeof(i));
#define Next(i, u) for(register int i = head[u]; i ; i = e[i].nxt)
#define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout);
#define Rep(i, a, b) for(register int i = (a) , i##Limit = (b) ; i <= i##Limit ; inc(i))
#define Dep(i, a, b) for(register int i = (a) , i##Limit = (b) ; i >= i##Limit ; dec(i))
int dx[10] = {1, -1, 0, 0};
int dy[10] = {0, 0, 1, -1};
using namespace std;
register int x = 0, f = 1; register char c = getchar();
while(c < ‘0‘ || c > ‘9‘) {if(c == ‘-‘) f = -1; c = getchar();}
while(c >= ‘0‘ && c <= ‘9‘) x = x * 10 + c - 48, c = getchar();
return x * f;
} long long Ans; int a[maxn];//, head[maxn];
priority_queue<int> Q[maxn]; vector<int> s, qwq[maxn];
// struct node { int nxt, to;} e[maxn << 1];
void merge(int x, int y) {
if(Q[x].size() < Q[y].size()) swap(Q[x], Q[y]);
while(Q[y].size()) {
s.push_back(max(Q[x].top(), Q[y].top()));
Q[x].pop(), Q[y].pop();
}
while(s.size()) Q[x].push(s.back()), s.pop_back();
}
void Dfs(int x) {
// Next(i, x) { int v = e[i].to; Dfs(v); merge(x, v);}
Rep(i, 0, qwq[x].size() - 1) Dfs(qwq[x][i]), merge(x, qwq[x][i]);
Q[x].push(a[x]);
}
signed main() { int t = read();
while(t --) { int n = read(), num = 0, sum = 0;
while(n % 2 == 0) n /= 2, num ++;
while(n % 3 == 0) n /= 3, sum ++;
if(n != 1) puts("-1");
else if(num > sum) puts("-1");
else printf("%d\n", num + (sum - num) * 2);
}
return 0;
}


(0)
(0)