#include <bits/stdc++.h>
using namespace std;
map<long long int, long long int> mp, mk;
set<long long int> s1, s2;
vector<long long int> v, w;
long long int a[2000006], b[2000006];
string s = "", p = "", q = "";
char ch;
long long int m, n, c, d, i, j, k, l, r, x, t, y, u, e, f, g, h, mn, mx;
int main() {
  cin >> t;
  while (t--) {
    cin >> n;
    while (n % 2 == 0) {
      n /= 2;
      c++;
    }
    while (n % 3 == 0) {
      n /= 3;
      d++;
    }
    if (n == 1 && c <= d)
      e = 2 * d - c;
    else
      e = -1;
    cout << e << endl;
    c = 0;
    d = 0;
  }
}
