#include <bits/stdc++.h>
int main() {
  using namespace std;
  int n, i, j;
  long long x = 0;
  long long k = 0;
  cin >> n;
  long long mas[1001];
  for (i = 0; i < n; i++) cin >> mas[i];
  for (i = 0; i < n; i++) {
    if (mas[i] < 2)
      cout << "0" << endl;
    else {
      x = mas[i];
      for (j = x; x > 1; j++) {
        if (x % 2 == 0) {
          x = x / 2;
          k++;
        }
        if (x % 3 == 0) {
          x = 2 * x / 3;
          k++;
        }
        if (x % 5 == 0) {
          x = 4 * x / 5;
          k++;
        }
        if (x == 1)
          cout << k << endl;
        else if (x % 2 != 0 && x % 3 != 0 && x % 5 != 0) {
          cout << "-1" << endl;
          k = 0;
          break;
        }
      }
      k = 0;
    }
  }
}
