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