#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t = 0, a, b, c = 0;
  cin >> t;
  for (int i = 0; i < t; i++) {
    cin >> a;
    while (a > 1) {
      if (a % 6 == 0) {
        a = a / 6;
      } else {
        a = a * 2;
      }
      c += 1;
    }
    if (a == 1) {
      cout << c << endl;
    } else
      cout << "-1" << endl;
    c = 0;
  }
  return 0;
}
