#include <bits/stdc++.h>
using namespace std;
const long long mxn = 100010;
void solve(long long tc) {
  long long n;
  cin >> n;
  long long two = 0, three = 0;
  while (n % 2 == 0) two++, n /= 2;
  while (n % 3 == 0) three++, n /= 3;
  if (n != 1)
    cout << -1 << '\n';
  else {
    if (two <= three) {
      cout << three - two + three << '\n';
    } else {
      cout << -1 << '\n';
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long tc;
  cin >> tc;
  for (long long t = (1), ed = (tc + 1); t < (ed); ++t) solve(t);
  return 0;
}
