#include <bits/stdc++.h>
using namespace std;
void solve() {
  int N;
  cin >> N;
  int n2 = 0, n3 = 0;
  while (N % 2 == 0) n2++, N /= 2;
  while (N % 3 == 0) n3++, N /= 3;
  int ans = -1;
  if (N == 1 && n2 <= n3) ans = (n3 - n2) + n3;
  cout << ans << endl;
}
int main() {
  int T;
  cin >> T;
  while (T--) solve();
  return 0;
}
