#include <bits/stdc++.h>
using namespace std;
const int inf = INT_MAX;
const long long INF = LLONG_MAX;
const int N = 100005;
long long q, n, ans;
bool f;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> q;
  for (int i = 0; i < q; ++i) {
    cin >> n;
    f = 1;
    while (n > 1) {
      f = 0;
      if (!(n % 2)) {
        n = n / 2;
        f = 1;
      } else {
        if (!(n % 3)) {
          n = 2 * n / 3;
          f = 1;
        } else {
          if (!(n % 5)) {
            n = 4 * n / 5;
            f = 1;
          }
        }
      }
      if (!f) {
        break;
      }
      ++ans;
    }
    if (!f) {
      cout << "-1\n";
    } else {
      cout << ans << "\n";
    }
    ans = 0;
  }
  return 0;
}
