#include <bits/stdc++.h>
using namespace std;
int divcount(unsigned long long int n) {
  int cnt = 0;
  while (n % 2 == 0) {
    n /= 2;
    cnt++;
  }
  while (n % 3 == 0) {
    n /= 3;
    cnt += 2;
  }
  while (n % 5 == 0) {
    n /= 5;
    cnt += 3;
  }
  if (n == 1)
    return cnt;
  else
    return -1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int t;
  cin >> t;
  unsigned long long int n;
  while (t--) {
    cin >> n;
    cout << divcount(n) << "\n";
  }
}
