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