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