#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (a == 0) return b;
  if (b == 0) return a;
  if (a == b) return a;
  if (a > b) {
    return gcd(a - b, b);
  }
  return gcd(a, b - a);
}
bool isPrime(int a) {
  if (a <= 1) return false;
  if (a == 2) return true;
  if (a > 2) {
    for (int i = 2; i < a; i++) {
      if (a % i == 0) return false;
    }
  }
  return true;
}
void solve() {
  long long n;
  cin >> n;
  long long c2 = 0, c3 = 0, c5 = 0;
  while (n % 2 == 0) {
    n /= 2;
    c2++;
  }
  while (n % 3 == 0) {
    n /= 3;
    c3++;
  }
  while (n % 5 == 0) {
    n /= 5;
    c5++;
  }
  if (n != 1) {
    cout << -1 << '\n';
    ;
  } else {
    cout << c2 + c3 * 2 + c5 * 3 << '\n';
    ;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
