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