#include <bits/stdc++.h>
using namespace std;
int pcalc(long long x, int a) {
  int m = 0;
  while (x % a == 0 && x >= a) {
    x /= a;
    m++;
  }
  return m;
}
void solve() {
  long long x;
  cin >> x;
  int n3 = pcalc(x, 3);
  int n2 = pcalc(x, 2);
  if ((n3 >= n2) && n3 != 0) {
    x *= pow(2, n3 - n2);
    x /= (long long)pow(6, n3);
    if (x == 1) {
      cout << 2 * n3 - n2 << '\n';
    } else
      cout << -1 << '\n';
  } else if (x == 1)
    cout << 0 << '\n';
  else {
    cout << -1 << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
