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