#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using lld = long double;
const ll oo = 0x3f3f3f3f;
const ll MOD = 1000000007;
const ll N = 1e9 + 10;
map<ll, ll> dis;
inline void insert(const ll& x, const ll& p, queue<ll>& q) {
  if (x >= N) return;
  if (!dis.count(x)) {
    q.push(x);
    dis[x] = 1 + dis[p];
  }
}
void bfs(ll src = 1) {
  queue<ll> q;
  q.push(src);
  dis[src] = 0;
  while (!q.empty()) {
    ll t = q.front();
    q.pop();
    if (t % 2 == 0) insert(t / 2, t, q);
    insert(t * 6, t, q);
  }
}
void solve() {
  ll n;
  cin >> n;
  if (!dis.count(n))
    cout << "-1\n";
  else
    cout << dis[n] << '\n';
  return;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  bfs();
  ll tc;
  cin >> tc;
  while (tc--) {
    solve();
  }
  return 0;
}
