#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n, c(0), d(0);
    scanf("%d", &n);
    while (n != 1) {
      ++c;
      if (d > 1) {
        c = -1;
        break;
      } else if (n % 6 == 0) {
        n /= 6;
        d = 0;
      } else {
        d++;
        n *= 2;
      }
    }
    printf("%d\n", c);
    ;
  }
}
