#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int q;
  cin >> q;
  while (q--) {
    long long n;
    cin >> n;
    long long cant = 0;
    long long c = 0;
    while (n > 1) {
      if (n % 2 == 0)
        n /= 2;
      else if (n % 3 == 0) {
        n /= 3;
        n *= 2;
      } else if (n % 5 == 0) {
        n /= 5;
        n *= 4;
      } else {
        cant = 1;
        break;
      }
      c++;
    }
    if (cant)
      cout << -1 << '\n';
    else
      cout << c << '\n';
  }
  return 0;
}
