#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    long long x = 1, y = 1;
    int cnt1 = 0, cnt2 = 0;
    while (n % (x * 2) == 0) cnt1++, x *= 2;
    while (n % (y * 3) == 0) cnt2++, y *= 3;
    while (n > 1 && n % 2 == 0) n /= 2;
    while (n > 1 && n % 3 == 0) n /= 3;
    if (n > 1 || cnt1 > cnt2)
      cout << "-1\n";
    else {
      cout << cnt2 + (cnt2 - cnt1) << '\n';
    }
  }
  return 0;
}
