#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int q, n, i = 1, ttl = 0;
  cin >> q;
  while (q--) {
    cin >> n;
    if (n <= 1) {
      cout << ttl << endl;
    } else {
      while (n != 1) {
        if (n % 2 == 0 || n % 3 == 0 || n % 5 == 0) {
          if (i <= 4) {
            if (n % (i + 1) == 0) {
              ttl++;
              n = i * (n / (i + 1));
            } else {
              i *= 2;
            }
          } else {
            i = 1;
          }
        } else {
          break;
        }
      }
      if (n > 1) {
        cout << -1 << endl;
      } else {
        cout << ttl << endl;
      }
      ttl = 0;
    }
  }
}
