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