#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    long long int tc = 0, thc = 0;
    while (n % 2 == 0) {
      tc++;
      n /= 2;
    }
    while (n % 3 == 0) {
      thc++;
      n /= 3;
    }
    if (n == 1 and thc >= tc)
      cout << (2 * thc - tc) << "\n";
    else
      cout << "-1\n";
  }
  return 0;
}
