#include <bits/stdc++.h>
using namespace std;
int q, c, f;
long long n;
int main() {
  cin >> q;
  for (int i = 1; i <= q; i++) {
    cin >> n;
    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 / 5 * 4;
      } else {
        cout << "-1" << endl;
        f = 1;
        break;
      }
      c++;
    }
    if (f != 1) {
      cout << c << endl;
    }
    c = 0;
    f = 0;
  }
  return 0;
}
