#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  vector<int> vec;
  int t;
  cin >> t;
  while (t--) {
    int cnt = 0;
    long long n;
    cin >> n;
    while (n > 1) {
      if (n % 6 == 0)
        n = n / 6;
      else
        n = n * 2;
      cnt++;
    }
    if (n == 1)
      cout << cnt << '\n';
    else
      cout << -1 << '\n';
  }
  return 0;
}
