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