#include <bits/stdc++.h>
using namespace std;
void init() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  init();
  int t;
  cin >> t;
  for (int _ = 0; _ < t; _++) {
    int n;
    cin >> n;
    int a = 0, b = 0;
    while (n % 2 == 0) {
      n /= 2;
      a++;
    }
    while (n % 3 == 0) {
      n /= 3;
      b++;
    }
    if (a > b || n != 1) {
      cout << "-1\n";
    } else {
      cout << (b + (b - a)) << '\n';
    }
  }
  return 0;
}
