#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, x, y, t, i, j, cnt2, k, cnt3;
  cin >> t;
  for (i = 0; i < t; i++) {
    cin >> x;
    k = 0;
    cnt2 = 0;
    cnt3 = 0;
    while ((x % 2) == 0) {
      x /= 2;
      cnt2++;
    }
    while ((x % 3) == 0) {
      x /= 3;
      cnt3++;
    }
    if (x > 1) {
      k = -1;
    } else if (x == 1) {
      if (cnt2 <= cnt3) {
        k = (cnt3 - cnt2) + cnt3;
      } else if (cnt3 < cnt2) {
        k = -1;
      }
    }
    cout << k << "\n";
  }
  return 0;
}
