#include <bits/stdc++.h>
using namespace std;
const int N = 107;
const int MAX = 1e6 + 7;
long long n, ans;
void init() { cin >> n; }
void solve() {
  bool flag = true;
  ans = 0;
  while (n != 1) {
    flag = false;
    while (n % 2 == 0) {
      flag = true;
      ans++;
      n /= 2;
    }
    while (n % 3 == 0) {
      flag = true;
      ans++;
      n /= 3;
      n *= 2;
    }
    while (n % 5 == 0) {
      flag = true;
      ans++;
      n /= 5;
      n *= 4;
    }
    if (!flag) break;
  }
  if (n != 1) ans = -1;
  printf("%d\n", ans);
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    init();
    solve();
  }
  return 0;
}
