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