#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t, n;
  cin >> t;
  while (t--) {
    cin >> n;
    int d = 0, tr = 0;
    while (n % 2 == 0) {
      n /= 2;
      d++;
    }
    while (n % 3 == 0) {
      n /= 3;
      tr++;
    }
    if (n > 1 || d > tr) {
      cout << -1 << "\n";
    } else {
      cout << tr + (tr - d) << "\n";
    }
  }
}
