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