#include <bits/stdc++.h>
using namespace std;
long long int solve() {
  long long int n;
  cin >> n;
  long long int cnt2 = 0;
  long long int cnt3 = 0;
  while (n % 2 == 0) {
    n /= 2;
    cnt2++;
  }
  while (n % 3 == 0) {
    n /= 3;
    cnt3++;
  }
  if (n > 1) return -1;
  if (cnt2 > cnt3) return -1;
  return cnt3 - cnt2 + cnt3;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) cout << solve() << endl;
}
