#include <bits/stdc++.h>
using namespace std;
const long long N = (long long)(1e6) + 322;
const long long INF = 2e18 + 17;
const long long inf = 2e9;
const long long mod = 1000000007;
const double eps = 1e-9;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long binpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n) {
    if (n & 1) {
      res *= a;
      res %= mod;
    }
    a *= a;
    a %= mod;
    n >>= 1;
  }
  return res;
}
long long q, odd[N], even[N], a[N], cnt, n;
signed main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long compt = 0, fl = 1, t = n;
    for (long long i = 1; i <= n; ++i) {
      if (t == 1)
        break;
      else if (t % 2 == 0) {
        t = t / 2;
        compt++;
      } else if (t % 3 == 0) {
        t = (2 * t) / 3;
        compt++;
      } else if (t % 5 == 0) {
        t = (4 * t) / 5;
        compt++;
      } else {
        fl = -1;
        break;
      }
    }
    if (fl == 1)
      cout << compt << endl;
    else
      cout << fl << endl;
  }
  return 0;
}
