#include <bits/stdc++.h>
using namespace std;
template <typename Number>
Number gcd(Number u, Number v) {
  while (v != 0) {
    Number r = u % v;
    u = v;
    v = r;
  }
  return u;
}
long long int binSearch(vector<long long int> v, long long int l,
                        long long int r, long long int x) {
  if (r >= l) {
    long long int mid = l + (r - l) / 2;
    if (v[mid] == x) return mid;
    if (v[mid] > x) return binSearch(v, l, mid - 1, x);
    return binSearch(v, mid + 1, r, x);
  }
  return -1;
}
void solve() {
  long long int n;
  cin >> n;
  long long int temp = n;
  long long int po2 = 0, po3 = 0;
  while (n % 2 == 0 || n % 3 == 0) {
    if (n % 2 == 0) {
      po2++;
      n /= 2;
    }
    if (n % 3 == 0) {
      po3++;
      n /= 3;
    }
  }
  if (n != 1) {
    cout << -1 << endl;
    return;
  }
  if (po2 > po3) {
    cout << -1 << endl;
    return;
  }
  long long int ans = 0;
  ans = (po3 - po2) + po3;
  cout << ans << endl;
  return;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
