#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, count = 0;
    cin >> n;
    for (int i = 0; n != 1; i++) {
      if (n % 6 == 0) {
        n = n / 6;
        count++;
      } else {
        n = n * 2;
        count++;
      }
      if (n > 1e9) {
        count = -1;
        break;
      }
    }
    cout << count << "\n";
  }
  return 0;
}
