#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, i;
  cin >> t;
  for (i = 0; i < t; i++) {
    int n, j;
    int cnt = 0, cnt_1 = 0, ans = -1;
    cin >> n;
    while (n % 2 == 0) {
      cnt++;
      n = n / 2;
    }
    while (n % 3 == 0) {
      cnt_1++;
      n = n / 3;
    }
    if (n == 1 && cnt <= cnt_1) {
      ans = cnt_1 - cnt;
      ans = ans + cnt_1;
    } else {
      ans = -1;
    }
    cout << ans << endl;
  }
}
