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