#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll t;
  cin >> t;
  while (t--) {
    ll cnt3, cnt2;
    cnt2 = cnt3 = 0;
    ll n;
    cin >> n;
    while (n % 2 == 0) {
      n = n / 2;
      cnt2++;
    }
    while (n % 3 == 0) {
      n = n / 3;
      cnt3++;
    }
    if (n != 1 || cnt2 > cnt3)
      cout << -1 << "\n";
    else {
      ll ans = cnt2 + (cnt3 - cnt2) * 2;
      cout << ans << "\n";
    }
  }
  return 0;
}
