#include <bits/stdc++.h>
using namespace std;
int q;
long long n;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> q;
  while (q--) {
    cin >> n;
    int res = 0;
    while (n != 1) {
      if (n % 2 == 0) {
        n /= 2;
        res++;
      } else if (n % 3 == 0) {
        n = (n / 3) * 2;
        res++;
      } else if (n % 5 == 0) {
        n = (n / 5) * 4;
        res++;
      } else
        break;
    }
    if (n != 1)
      cout << -1 << endl;
    else
      cout << res << endl;
  }
  return 0;
}
