#include <bits/stdc++.h>
using namespace std;
void solve_with_case(int cas) { cout << "Case " << ++cas << ": "; }
void solve_without_case() {
  long long x, cnt = 0;
  cin >> x;
  while (x > 1) {
    if (x % 6 == 0) {
      x /= 6;
      cnt++;
    }
    if (x != 1 && x % 6 != 0) {
      x *= 2;
      cnt++;
    }
  }
  if (x < 1) cnt = -1;
  cout << cnt << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  ;
  int t, cas = 0;
  cin >> t;
  while (t--) {
    solve_without_case();
    cas++;
  }
}
