#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, i = 0, j = 0, l, x, y;
    cin >> n;
    x = n;
    y = n;
    while (x % 3 == 0 || x % 2 == 0) {
      if (x % 3 == 0) {
        x = x / 3;
        i++;
      } else {
        x = x / 2;
        j++;
      }
    }
    if (j > i || x != 1)
      cout << -1;
    else
      cout << i - j + i;
    cout << "\n";
  }
  return 0;
}
