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