#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int n, c = 0, k, x = 0, d, i, j, ans = 0;
    cin >> n;
    while (n != 1) {
      if (n % 2 == 0) {
        n = n / 2;
        ans++;
      } else if (n % 3 == 0) {
        n = n / 3;
        ans += 2;
      } else if (n % 5 == 0) {
        n = n / 5;
        ans += 3;
      } else {
        c = 1;
        break;
      }
      if (n == 1) break;
    }
    if (c == 1)
      cout << -1 << endl;
    else
      cout << ans << endl;
  }
  return 0;
}
