#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long cnt = 0;
    int k = n;
    int a = 0, b = 0;
    while (1) {
      if (k % 2 != 0) break;
      k /= 2;
      a++;
    }
    while (1) {
      if (k % 3 != 0) break;
      k /= 3;
      b++;
    }
    if (a > b || k != 1) {
      cout << -1 << '\n';
    } else {
      cout << a + 2 * (b - a) << '\n';
    }
  }
}
