#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 1e6 + 5;
const int INF = 0x3f3f3f3f;
const long long LINF = (long long)2e18;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long a = 0, b = 0, p = n, c = 0;
    while (p > 1) {
      if (p % 2 == 0) {
        a++;
        p /= 2;
      } else if (p % 3 == 0) {
        b++;
        p /= 3;
      } else {
        c++;
        break;
      }
    }
    if (c)
      cout << -1 << "\n";
    else if (b < a)
      cout << -1 << "\n";
    else
      cout << 2 * b - a << "\n";
  }
  return 0;
}
