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