#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  uint64_t t;
  cin >> t;
  while (t--) {
    uint64_t n;
    cin >> n;
    uint64_t ans = 0;
    while (true) {
      if (n == 1) {
        cout << ans << '\n';
        break;
      }
      if (n % 5 == 0)
        n -= n / 5;
      else if (n % 3 == 0)
        n -= n / 3;
      else if (n % 2 == 0)
        n = n / 2;
      else {
        cout << "-1\n";
        break;
      }
      ans++;
    }
  }
}
