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