#include <bits/stdc++.h>
using namespace std;
void input_output() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
bool is_prime(int n) {
  if (n < 2) return false;
  int i;
  for (i = 2; i < (int)sqrt(n) + 1; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
bool is_palindrome(string s) {
  int i;
  for (i = 0; i < s.size() / 2; i++) {
    if (s[i] != s[s.size() - i - 1]) return false;
  }
  return true;
}
int no_of_primes = 10;
vector<bool> prime(no_of_primes + 1, true);
vector<int> prime_nums;
void sieve_of_erat() {
  prime[0] = false;
  prime[1] = false;
  int i, j;
  for (i = 2; i < (int)sqrt(no_of_primes) + 1; i++) {
    if (prime[i] == false) continue;
    j = 2 * i;
    while (j <= no_of_primes) {
      prime[j] = false;
      j += i;
    }
  }
  for (i = 0; i < no_of_primes + 1; i++) {
    if (prime[i] == true) prime_nums.push_back(i);
  }
}
vector<vector<int> > adj(1001);
int bfs(int si, int n) {
  vector<bool> visited(n + 1, false);
  vector<int> dist(n + 1, -1);
  dist[si] = 0;
  queue<int> q;
  q.push(si);
  int i;
  while (!q.empty()) {
    int temp = q.front();
    q.pop();
    for (i = 0; i < adj[temp].size(); i++) {
      if (!visited[adj[temp][i]]) {
        q.push(adj[temp][i]);
        dist[adj[temp][i]] = dist[temp] + 1;
        visited[adj[temp][i]] = true;
      }
    }
  }
  return *max_element(dist.begin(), dist.end());
}
void read_arr(vector<int> &v, int n) {
  int i;
  for (i = 0; i < n; i++) cin >> v[i];
}
void solve() {
  long long n;
  cin >> n;
  int two = 0, three = 0;
  int i;
  long long k = n;
  while (n % 2 == 0) {
    n /= 2;
    two++;
  }
  n = k;
  while (n % 3 == 0) {
    n /= 3;
    three++;
  }
  n = k;
  if (pow(2, two) * pow(3, three) == n) {
    if (two <= three)
      cout << three + (three - two);
    else
      cout << -1;
  } else
    cout << -1;
  cout << '\n';
}
int main() {
  input_output();
  int t;
  cin >> t;
  while (t--) solve();
}
