#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 9;
long long power(long long x, long long y) {
  if (y == 0) return 1;
  long long temp = power(x, y / 2);
  if (y % 2 == 1)
    return temp * temp * x;
  else
    return temp * temp;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long s1 = 0, s2 = 0;
    while (n % 2 == 0) {
      s1++;
      n /= 2;
    }
    while (n % 3 == 0) {
      s2++;
      n /= 3;
    }
    if (n == 1) {
      if (s1 <= s2) {
        long long ans = min(s1, s2);
        s1 -= ans;
        s2 -= ans;
        ans += s2 * 2;
        cout << ans << "\n";
      } else {
        cout << "-1\n";
      }
    } else
      cout << "-1\n";
  }
  return 0;
}
