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