#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long counter = 0;
    while (n != 1) {
      if (n % 2 != 0) {
        n = n * 2;
        counter++;
      } else {
        if (n % 6 != 0) {
          counter = -1;
          break;
        }
        n = n / 6;
        counter++;
      }
    }
    cout << counter << endl;
  }
  return 0;
}
