#include <bits/stdc++.h>
long long int numCycles(long long int n) {
  int result = 0;
  while (0 == n % 2) {
    n /= 2;
    ++result;
  }
  while (0 == n % 3) {
    n /= 3;
    result += 2;
  }
  while (0 == n % 5) {
    n /= 5;
    result += 3;
  }
  if (n != 1) {
    return -1;
  }
  return result;
}
int main() {
  int numQueries;
  std::cin >> numQueries;
  for (int i = 0; i < numQueries; ++i) {
    long long int tmp;
    std::cin >> tmp;
    int result = numCycles(tmp);
    std::cout << result << '\n';
  }
  return 0;
}
