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