#include <bits/stdc++.h>
using namespace std;
const int MA = 2e5 + 5;
int a[MA];
int T;
long long n;
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%lld", &n);
    int ans = 0;
    while (n != 1) {
      if (n % 2 == 0) {
        n /= 2;
        ans++;
      } else if (n % 3 == 0) {
        ans += 2;
        n /= 3;
      } else if (n % 5 == 0) {
        ans += 3;
        n /= 5;
      } else {
        break;
      }
    }
    if (n == 1) {
      printf("%d\n", ans);
    } else
      printf("-1\n");
  }
  return 0;
}
