#include <bits/stdc++.h>
template <typename T>
constexpr int len(const T& container) {
  return container.size();
}
using ll = long long;
using namespace std;
int INF = 1e9 + 5;
pair<ll, ll> dirs[4] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
template <typename T, typename A>
int argmax(std::vector<T, A> const& vec) {
  return static_cast<int>(
      std::distance(vec.begin(), max_element(vec.begin(), vec.end())));
}
template <typename T, typename A>
int argmin(std::vector<T, A> const& vec) {
  return static_cast<int>(
      std::distance(vec.begin(), min_element(vec.begin(), vec.end())));
}
ll N = 0;
unordered_map<ll, ll> memo;
ll brute(ll n) {
  if (memo.find(n) != memo.end()) return memo[n];
  if (n == 1) return 0;
  if (n > 6 * N) return INF;
  ll result = INF;
  if (n % 6 == 0) result = min(result, 1 + brute(n / 6));
  result = min(result, 1 + brute(2 * n));
  memo[n] = result;
  return result;
}
int main() {
  ll t;
  cin >> t;
  for (auto i = 0; i < t; ++i) {
    ll n;
    cin >> n;
    N = n;
    auto result = brute(n);
    if (result >= INF) result = -1;
    cout << result << "\n";
  }
}
