#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  long long ca;
  cin >> ca;
  while (ca--) {
    long long n, i, j, k;
    cin >> n;
    long long cnt = 0;
    while (1) {
      if (n % 2 == 0)
        n = n / 2;
      else if (n % 3 == 0)
        n = (2 * n) / 3;
      else if (n % 5 == 0)
        n = (n * 4) / 5;
      else
        break;
      cnt++;
    }
    if (n == 1)
      cout << cnt << endl;
    else
      cout << -1 << endl;
  }
  return 0;
}
