#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  long long n, res;
  while (q--) {
    cin >> n;
    res = 0;
    while (n > 1) {
      if (n % 2 == 0)
        n /= 2;
      else if (n % 3 == 0)
        n = n / 3 * 2;
      else if (n % 5 == 0)
        n = n * 4 / 5;
      else {
        res = -1;
        break;
      }
      res++;
    }
    cout << res << '\n';
  }
  return 0;
}
