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