#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  cin >> t;
  while (t--) {
    long long n, cnt = 0, cnt2 = 0;
    cin >> n;
    while (n % 3 == 0) {
      n /= 3;
      cnt++;
    }
    while (n % 2 == 0) {
      n /= 2;
      cnt2++;
    }
    if (n > 1) {
      cout << -1 << "\n";
    } else if (cnt < cnt2) {
      cout << -1 << "\n";
    } else {
      long long x = cnt - cnt2;
      cout << cnt + x << "\n";
    }
  }
  return 0;
}
