#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    long long int t = n;
    int cthree = 0;
    int ctwo = 0;
    while (t % 3 == 0) {
      cthree++;
      t /= 3;
    }
    while (t % 2 == 0) {
      ctwo++;
      t /= 2;
    }
    if (ctwo > cthree || t != 1) {
      cout << -1 << endl;
    } else {
      t = cthree - ctwo;
      t += cthree;
      cout << t << endl;
    }
  }
}
