#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int x;
    cin >> x;
    long long int ans = 0;
    while (x % 5 == 0) {
      x = 4 * x / 5;
      ans++;
    }
    while (x % 3 == 0) {
      x = 2 * x / 3;
      ans++;
    }
    while (x % 2 == 0) {
      x /= 2;
      ans++;
    }
    if (x != 1) {
      ans = -1;
    }
    cout << ans << endl;
  }
}
