#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n;
  cin >> n;
  long long int ans = 0;
  while (n % 2 == 0) {
    ans++;
    n = n / 2;
  }
  while (n % 3 == 0) {
    ans += 2;
    n = n / 3;
  }
  while (n % 5 == 0) {
    ans += 3;
    n = n / 5;
  }
  if (n != 1) ans = -1;
  cout << ans << endl;
}
signed main() {
  long long int t = 1;
  cin >> t;
  for (long long int tc = 1; tc <= t; tc++) {
    solve();
  }
}
