#include <bits/stdc++.h>
using namespace std;
const int N = 1e7;
void solve() {
  long long n, two = 0, thre = 0;
  cin >> n;
  if (n == 1)
    cout << 0;
  else {
    while (n % 2 == 0 || n % 3 == 0) {
      while (n % 2 == 0) {
        two++;
        n = n / 2;
      }
      while (n % 3 == 0) {
        thre++;
        n = n / 3;
      }
    }
    if (n != 1 || two > thre)
      cout << -1;
    else {
      long long diff = thre - two;
      cout << thre + diff;
    }
  }
  cout << endl;
}
int main() {
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}
