#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  long long k = n;
  long long n1 = 0, n2 = 0, n3 = 0;
  while (k % 2 == 0) {
    k = k / 2;
    n1++;
  }
  k = n;
  while (k % 3 == 0) {
    k /= 3;
    n2++;
  }
  k = n;
  while (k % 5 == 0) {
    k /= 5;
    n3++;
  }
  long long p = 1;
  for (long long i = 0; i < n1; i++) p *= 2;
  for (long long i = 0; i < n2; i++) p *= 3;
  for (long long i = 0; i < n3; i++) p *= 5;
  if (p != n)
    cout << -1 << '\n';
  else
    cout << n1 + 2 * n2 + 3 * n3 << '\n';
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
