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