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