#include <bits/stdc++.h>
long no_of_factors(long long n) {
  long s = 0;
  while (n % 2 == 0) {
    n /= 2;
    s++;
  }
  while (n % 3 == 0) {
    n /= 3;
    s += 2;
  }
  while (n % 5 == 0) {
    n /= 5;
    s += 3;
  }
  if (n != 1) return -1;
  return s;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    long long n;
    scanf("%lld", &n);
    long x = no_of_factors(n);
    printf("%ld\n", x);
  }
}
