#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, i, j, k, w, l, count = 0;
    cin >> n;
    if (n == 1) {
      cout << 0 << "\n";
    } else {
      while (n > 1 && (n % 3 == 0 || n % 2 == 0 || n % 5 == 0)) {
        if (n % 2 == 0) {
          n = n / 2;
          count++;
        } else if (n % 3 == 0) {
          n = (2 * n) / 3;
          count++;
        } else if (n % 5 == 0) {
          n = (n * 4) / 5;
          count++;
        }
      }
      if (n == 1) {
        cout << count << "\n";
      } else {
        cout << -1 << "\n";
      }
    }
  }
  return 0;
}
