#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  fast();
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    long long int fact2 = 0, fact3 = 0;
    while (n % 2 == 0) {
      n = n / 2;
      fact2++;
    }
    while (n % 3 == 0) {
      n = n / 3;
      fact3++;
    }
    if (n != 1) {
      cout << "-1\n";
      continue;
    }
    if (fact3 < fact2) {
      cout << "-1\n";
      continue;
    }
    cout << fact3 + abs(fact3 - fact2) << '\n';
  }
}
