#include <bits/stdc++.h>
using namespace std;
long long n, t;
int main() {
  int q;
  cin >> q;
  while (q--) {
    cin >> n;
    t = 0;
    while (n % 2 == 0) n /= 2, t++;
    while (n % 3 == 0) n /= 3, t += 2;
    while (n % 5 == 0) n /= 5, t += 3;
    cout << (n == 1 ? t : -1) << endl;
  }
  return 0;
}
