#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<ld, ld>;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<ld>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;
const int MIN = 2e5 + 20;
const int MAX = 1e9 + 20;
ll n, k, a, b, l, i, j, t, u[3], mn, r, v;
pair<ll, ll> p[1000];
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> n;
    l = 1;
    k = 0;
    while (n > 1) {
      if (n % 2 == 0)
        n /= 2;
      else if (n % 3 == 0)
        n = (n / 3) * 2;
      else if (n % 5 == 0)
        n = (n / 5) * 4;
      else {
        l = 0;
        break;
      }
      k++;
    }
    if (l)
      cout << k << '\n';
    else
      cout << "-1\n";
  }
}
