#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long q;
  cin >> q;
  while (q--) {
    long long n;
    cin >> n;
    long long cn = 0;
    while (n % 3 == 0) {
      cn += 2;
      n /= 3;
    }
    while (n % 5 == 0) {
      cn += 3;
      n /= 5;
    }
    while (n % 2 == 0) {
      cn++;
      n /= 2;
    }
    if (n == 1) {
      cout << cn << endl;
    } else {
      cout << -1 << endl;
    }
  }
  return 0;
}
