#include <bits/stdc++.h>
using namespace std;
vector<int32_t> dp(1, 0);
void solve() {
  int64_t n;
  cin >> n;
  int64_t x3 = 0, x2 = 0;
  while (n % 3 == 0 && n != 1) {
    n /= 3;
    x3++;
  }
  while (n % 2 == 0 && n != 1) {
    n /= 2;
    x2++;
  }
  if (x3 >= x2 && n == 1) {
    cout << x3 + (x3 - x2) << '\n';
  } else {
    cout << -1 << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t_;
  cin >> t_;
  while (t_--) solve();
  return 0;
}
