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