#include <bits/stdc++.h>
using namespace std;
bool comp(pair<long long int, long long int> &a,
          pair<long long int, long long int> &b) {
  if (a.first == b.first) return a.second > b.second;
  return a.first < b.first;
}
int main() {
  int tc;
  cin >> tc;
  while (tc--) {
    long long int n, k, two = 0, three = 0, five = 0;
    cin >> n;
    k = n;
    while (n % 2 == 0) two++, n /= 2;
    while (n % 3 == 0) three++, n /= 3;
    while (n % 5 == 0) five++, n /= 5;
    if (n != 1)
      cout << -1 << '\n';
    else {
      cout << two + (2 * three) + (3 * five) << '\n';
    }
  }
}
