#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int n, m, i, ans = 0, j, f = 0, x, c = 0;
    cin >> n;
    if (n == 1) {
      cout << "0" << endl;
      continue;
    }
    for (i = 0; i < 30; i++) {
      j = n * pow(2ll, i);
      c = 1ll;
      x = 6ll;
      while (x <= j && x > 0) {
        x = pow(6ll, c);
        if (j % x == 0 && j / x == 1) {
          ans = i + c;
          f = 1;
          break;
        } else
          c++;
      }
      if (f == 1) break;
    }
    if (ans == 0)
      cout << "-1" << endl;
    else
      cout << ans << endl;
  }
  return 0;
}
