#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, x = 0, c = 0;
    cin >> n;
    while (n != 1) {
      if (x == 3) {
        cout << "-1" << endl;
        break;
      }
      if (n % 6 == 0) {
        n /= 6;
        c++;
        x = 0;
      } else {
        n *= 2;
        c++;
        x++;
      }
    }
    if (n == 1) {
      cout << c << endl;
    }
  }
  return 0;
}
