#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long two = 0, three = 0;
    if (n == 1) {
      cout << 0 << '\n';
      continue;
    }
    while (n) {
      if (n % 2 == 0) {
        two++;
        n /= 2;
      } else {
        break;
      }
    }
    while (n && n != 1) {
      if (n % 3 == 0) {
        three++;
        n /= 3;
      } else {
        break;
      }
    }
    if (n != 1) {
      cout << -1 << '\n';
    } else {
      if (two > three) {
        cout << -1 << '\n';
      } else {
        long long ans = three - two;
        ans += three;
        cout << ans << '\n';
      }
    }
  }
}
