#include <bits/stdc++.h>
using namespace std;
int main() {
  int q, i, val = 0;
  scanf("%d", &q);
  long long int n;
  while (q--) {
    scanf("%lld", &n);
    if (n == 1)
      printf("0\n");
    else {
      val = 0;
      while (n != 1) {
        if (n % 2 == 0) {
          n = n / 2;
          val++;
        } else if (n % 3 == 0) {
          n = (2 * n) / 3;
          val++;
        } else if (n % 5 == 0) {
          n = (4 * n) / 5;
          val++;
        } else {
          val = -1;
          break;
        }
      }
      printf("%d\n", val);
    }
  }
}
