#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n;
  cin >> n;
  if (n == 1) {
    cout << 0 << "\n";
    return;
  }
  long long int count3 = 0;
  long long int count2 = 0;
  while (n % 3 == 0) {
    count3++;
    n /= 3;
  }
  while (n % 2 == 0) {
    count2++;
    n /= 2;
  }
  if (n != 1 || count3 < count2) {
    cout << "-1\n";
  } else {
    cout << 2 * count3 - count2 << "\n";
  }
}
int main() {
  int t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
