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