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