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