#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    int cnt2 = 0, cnt3 = 0;
    cin >> n;
    while (n % 3 == 0) {
      n /= 3;
      cnt3++;
    }
    while (n % 2 == 0) {
      n /= 2;
      cnt2++;
    }
    if (cnt2 > cnt3 || n != 1)
      cout << "-1" << endl;
    else
      cout << cnt3 - cnt2 + cnt3 << endl;
  }
  return 0;
}
