#include <bits/stdc++.h>
using namespace std;
vector<int> factor[500010];
int m, q;
long long n;
int p[10000], c[10000];
int divide(long long n) {
  int ans = 0;
  while (n % 5 == 0) n = n / 5 * 4, ans++;
  while (n % 3 == 0) n = n / 3 * 2, ans++;
  while (n % 2 == 0) n = n / 2, ans++;
  if (n > 1) return -1;
  return ans;
}
int main() {
  scanf("%d", &q);
  while (q--) {
    scanf("%lld", &n);
    int p = divide(n);
    if (p == -1)
      printf("-1\n");
    else
      printf("%d\n", p);
  }
  return 0;
}
