#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1);
const long long inf = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const int MAX = 2e5 + 10;
const long long mod = 1e9 + 7;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
  int q;
  cin >> q;
  while (q--) {
    long long x;
    cin >> x;
    int mark = 0;
    long long ans = 0;
    while (x != 1) {
      if (x % 2 == 0) {
        x /= 2;
        ans++;
      } else if (x % 3 == 0) {
        x = x / 3 * 2;
        ans++;
      } else if (x % 5 == 0) {
        x = x / 5 * 4;
        ans++;
      } else {
        cout << "-1" << '\n';
        mark = 1;
        break;
      }
    }
    if (mark == 0) cout << ans << '\n';
  }
}
