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