#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t;
  cin >> t;
  while (t--) {
    long long cnt = 0;
    long long n;
    cin >> n;
    while (n != 1) {
      if (n % 2 == 0) {
        cnt++;
        n /= 2;
      } else if (n % 3 == 0) {
        cnt++;
        n *= 2;
        n /= 3;
      } else if (n % 5 == 0) {
        cnt++;
        n *= 4;
        n /= 5;
      } else {
        cnt = -1;
        break;
      }
    }
    cout << cnt << '\n';
  }
}
