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