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