#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    long long int ans = 0;
    while (n != 1) {
      if (n % 2 == 0) {
        ans += 1;
        n /= 2;
      } else if (n % 3 == 0) {
        ans += 1;
        n = (2 * n) / 3;
      } else if (n % 5 == 0) {
        ans += 1;
        n = (4 * n) / 5;
      } else {
        cout << "-1\n";
        break;
      }
    }
    if (n == 1) cout << ans << "\n";
  }
  return 0;
}
