#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, n, ji, pan, sum, he, x, y;
  scanf("%lld", &t);
  while (t--) {
    ji = pan = sum = he = 0;
    scanf("%lld", &n);
    if (n == 1) {
      printf("0\n");
      pan = 1;
    } else if (n % 3 != 0) {
      printf("-1\n");
      pan = 1;
    } else {
      x = n;
      while (x % 2 == 0) {
        sum++;
        x /= 2;
      }
      while (x % 3 == 0) {
        he++;
        x /= 3;
      }
      if (x != 1) {
        printf("-1\n");
        pan = 1;
      } else {
        if (sum > he) {
          printf("-1\n");
          pan = 1;
        } else {
          y = he - sum;
          ji = sum + y * 2;
        }
      }
    }
    if (pan == 0) {
      printf("%lld\n", ji);
    }
  }
  return 0;
}
