#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
template <typename T, typename U>
inline void amin(T &x, U y) {
  if (y < x) x = y;
}
template <typename T, typename U>
inline void amax(T &x, U y) {
  if (x < y) x = y;
}
int n;
long long int solve() {
  long long int res = 0;
  int pow2 = 0;
  int pow3 = 0;
  int n2 = n;
  int n2a = 1;
  while (n2 % 2 == 0) {
    n2 /= 2;
    pow2++;
    n2a *= 2;
  }
  int n3b = 1;
  int n3 = n;
  while (n3 % 3 == 0) {
    n3 /= 3;
    pow3++;
    n3b *= 3;
  }
  if (n2a * n3b != n) {
    return -1;
  }
  if (pow2 > pow3) {
    return -1;
  }
  res = pow3;
  res += pow3 - pow2;
  return res;
}
int main() {
  int T;
  cin >> T;
  for (int t = 0; t < T; t += 1) {
    cin >> n;
    cout << solve() << endl;
  }
  return 0;
}
