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