#include <bits/stdc++.h>
using namespace std;
long long int count2 = 0, count3 = 0, count5 = 0;
bool check(long long int n) {
  count2 = 0, count3 = 0, count5 = 0;
  while (n % 2 == 0 && n > 0) {
    n /= 2;
    count2++;
  }
  while (n % 3 == 0) {
    n /= 3;
    count3++;
  }
  while (n % 5 == 0) {
    n /= 5;
    count5++;
  }
  if (n == 1) {
    return false;
  } else {
    return true;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  while (q--) {
    long long int n;
    cin >> n;
    bool flag = check(n);
    if (flag)
      cout << "-1"
           << "\n";
    else {
      long long int ans = count2 + 2 * count3 + 3 * count5;
      cout << ans << "\n";
    }
  }
  return 0;
}
