#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned long long int n, t;
  cin >> t;
  for (long long int i = 1; i <= t; i++) {
    cin >> n;
    if (n == 1) {
      cout << 0;
    } else {
      unsigned long long int r = 0, ck = 0;
      while (n > 1) {
        unsigned long long int a = r;
        if ((n & 1) == 0) {
          n = n / 2;
          r++;
        } else if (n % 3 == 0) {
          n = (n / 3) * 2;
          r++;
        } else if (n % 5 == 0) {
          n = (n / 5) * 4;
          r++;
        }
        if (a == r) {
          ck = 1;
          break;
        }
      }
      if (ck)
        cout << -1;
      else
        cout << r;
    }
    cout << endl;
  }
  return 0;
}
