#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  for (long long i = 0; i < t; i++) {
    long long n;
    cin >> n;
    if (n == 1)
      cout << 0 << endl;
    else {
      if (n % 3 == 0) {
        long long num = n, count = 0;
        while (num % 3 == 0) {
          num /= 3;
          count++;
        }
        if (num == 1)
          cout << 2 * count << endl;
        else {
          if (num % 2 == 0) {
            long long sum = 0;
            while (num % 2 == 0) {
              num /= 2;
              sum++;
            }
            if (num == 1) {
              long long d;
              if (sum <= count) {
                d = count - sum;
                cout << count + d << endl;
              } else
                cout << -1 << endl;
            } else
              cout << -1 << endl;
          } else
            cout << -1 << endl;
        }
      } else
        cout << -1 << endl;
    }
  }
  return 0;
}
