#include <bits/stdc++.h>
long long n, num, cnt;
int main() {
  scanf("%lld", &n);
  while (n--) {
    cnt = 0;
    scanf("%lld", &num);
    if (num == 1) {
      printf("0\n");
      continue;
    }
    long long tmp = num;
    while (tmp % 2 == 0) tmp /= 2;
    while (tmp % 3 == 0) tmp /= 3;
    while (tmp % 5 == 0) tmp /= 5;
    if (tmp != 1) {
      printf("-1\n");
      continue;
    }
    while (true) {
      if (num % 2 == 0) {
        num /= 2;
        cnt++;
      }
      if (num % 3 == 0) {
        num = 2 * num / 3;
        cnt++;
      }
      if (num % 5 == 0) {
        num = 4 * num / 5;
        cnt++;
      }
      if (num == 1) break;
    }
    printf("%lld\n", cnt);
  }
  return 0;
}
