#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
using ll = long long;
using P = pair<ll, ll>;
constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());
class ADivideIt {
 public:
  void solve(istream& cin, ostream& cout) {
    int n;
    cin >> n;
    for (int i = 0; i < (int)(n); i++) {
      ll a;
      cin >> a;
      int cnt = 0;
      while (a % 5 == 0) {
        cnt++;
        a /= 5;
        a *= 4;
      }
      while (a % 3 == 0) {
        cnt++;
        a /= 3;
        a *= 2;
      }
      while (a % 2 == 0) {
        cnt++;
        a /= 2;
      }
      if (a != 1) {
        cout << -1 << '\n';
      } else {
        cout << cnt << '\n';
      }
    }
  }
};
signed main() {
  ADivideIt solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}
