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