#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  while (q--) {
    long long count = 0;
    long long n;
    cin >> n;
    while (n % 5 == 0) {
      n /= 5;
      n *= 4;
      count++;
    }
    while (n % 3 == 0) {
      n /= 3;
      n *= 2;
      count++;
    }
    while (n % 2 == 0) {
      n /= 2;
      count++;
    }
    if (n == 1)
      cout << count << '\n';
    else
      cout << -1 << '\n';
  }
}
