#include <bits/stdc++.h>
using namespace std;
long long n, m, l, x, y, z, k;
int t, g, i;
const long long INF = 1e18;
void solve() {
  cin >> n;
  while (n--) {
    long long x;
    cin >> x;
    long long ans = 0;
    bool ok = true;
    while (x != 1 && ok) {
      if (x % 2 == 0) {
        x = x / 2;
        ++ans;
      } else if (x % 3 == 0) {
        x = 2 * x / 3;
        ++ans;
      } else if (x % 5 == 0) {
        x = 3 * x / 5;
        ++ans;
      } else {
        ans = -1;
        ok = false;
      }
    }
    cout << ans << endl;
  }
}
void fast_io() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  fast_io();
  solve();
}
