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