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