#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int b) {
  long long int result = 1;
  while (b > 0) {
    int lastbit = (b & 1);
    if (lastbit) {
      result = (result * a) % 1000000007;
    }
    a = (a * a) % 1000000007;
    b = b >> 1;
  }
  return result % 1000000007;
}
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
vector<int> SieveOfEratosthenes(int n) {
  bool prime[n + 1];
  memset(prime, true, sizeof(prime));
  for (int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (int i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
  vector<int> v;
  for (int p = 2; p <= n; p++)
    if (prime[p]) v.push_back(p);
  return v;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int tt;
  cin >> tt;
  while (tt--) {
    long long int n;
    cin >> n;
    int count = 0;
    while (n != 1) {
      if (n % 2 == 0) {
        n /= 2;
      } else if (n % 3 == 0) {
        n = 2 * (n / 3);
      } else if (n % 5 == 0) {
        n = 4 * (n / 5);
      } else {
        count = -1;
        break;
      }
      count++;
    }
    cout << count << endl;
  }
  return 0;
}
