#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    long long n, a[200009], c = 0, ct = 0;
    string s;
    cin >> n;
    while (n % 2 == 0) {
      n /= 2;
      ct++;
    }
    while (n % 3 == 0) {
      n /= 3;
      c++;
    }
    if (c < ct || n != 1)
      cout << "-1" << endl;
    else
      cout << c + (c - ct) << endl;
  }
  return 0;
}
