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