#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tests = 1;
  cin >> tests;
  while (tests--) {
    long long n;
    cin >> n;
    int cnt[2] = {0, 0};
    long long temp = n;
    while (temp % 2 == 0) {
      temp = temp / 2;
      cnt[0]++;
    }
    while (temp % 3 == 0) {
      temp = temp / 3;
      cnt[1]++;
    }
    if ((temp > 1) || (cnt[0] > cnt[1])) {
      cout << "-1" << endl;
    } else {
      cout << (cnt[1] + (cnt[1] - cnt[0])) << endl;
    }
  }
  return 0;
}
