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