#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, k = 0;
  cin >> n;
  while (n % 2 == 0 || n % 3 == 0 || n % 5 == 0) {
    k++;
    if (n % 2 == 0)
      n /= 2;
    else if (n % 3 == 0)
      n = 2 * n / 3;
    else if (n % 5 == 0)
      n = 4 * n / 5;
  }
  if (n == 1)
    cout << k << "\n";
  else
    cout << "-1"
         << "\n";
}
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(NULL);
  long long t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
