#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
map<long long, int> mp;
int main() {
  int n;
  cin >> n;
  while (n--) {
    mp.clear();
    long long x;
    cin >> x;
    int ans = 0;
    bool ok = true;
    while (x != 1) {
      ans++;
      if (x % 2 == 0)
        x /= 2;
      else if (x % 3 == 0)
        x = 2 * x / 3;
      else if (x % 5 == 0)
        x = 4 * x / 5;
      if (mp[x] != 0) {
        ok = false;
        break;
      }
      mp[x]++;
    }
    if (ok)
      cout << ans << endl;
    else
      cout << "-1" << endl;
  }
}
