#include <bits/stdc++.h>
using namespace std;
template <class T>
T GCD(T a, T b) {
  return (b != 0 ? GCD<T>(b, a % b) : a);
}
template <class T>
T LCM(T a, T b) {
  return ((a * b) / GCD<T>(a, b));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int q, n;
  cin >> q;
  long long int cnt = 0;
  while (q--) {
    cin >> n;
    cnt = 0;
    while (n != 1) {
      if (n % 2 == 0) {
        n /= 2;
        cnt++;
      } else if (n % 3 == 0) {
        n = (n / 3);
        cnt += 2;
      } else if (n % 5 == 0) {
        n = (n / 5);
        cnt += 3;
      } else {
        cnt = -1;
        break;
      }
    }
    cout << cnt << endl;
  }
  return 0;
}
