#include <bits/stdc++.h>
using namespace std;
long long read() {
  char a = getchar();
  long long c = 0, b = 1;
  while (a < '0' || a > '9') {
    if (a == '-') b = -1;
    a = getchar();
  }
  while (a >= '0' && a <= '9') c = c * 10 + a - 48, a = getchar();
  return c * b;
}
int main() {
  long long q = read();
  for (int i = 0; i < q; i++) {
    long long n = read(), a = 0;
    while (n != 1) {
      if (n % 2 == 0) n /= 2, a++;
      if (n % 3 == 0) n /= 3, a += 2;
      if (n % 5 == 0) n /= 5, a += 3;
      if (n % 3 != 0 && n % 5 != 0 && n % 2 != 0 && n != 1) {
        a = -1;
        break;
      }
    }
    cout << a << endl;
  }
  return 0;
}
