#include <bits/stdc++.h>
using namespace std;
int INF = INT_MAX;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int ans = 0;
    long long n;
    cin >> n;
    while (n % 5 == 0) {
      n /= 5;
      n *= 4;
      ans++;
    }
    while (n % 3 == 0) {
      n /= 3;
      n *= 2;
      ans++;
    }
    while (n % 2 == 0) {
      n /= 2;
      ans++;
    }
    if (n == 1) {
      cout << ans << endl;
    } else {
      cout << -1 << endl;
    }
  }
  return 0;
}
