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