#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6 + 5;
int main() {
  ios_base::sync_with_stdio(0);
  long long q;
  cin >> q;
  while (q--) {
    long long n;
    cin >> n;
    long long cnt = 0;
    long long flag = 1;
    while (n != 1) {
      if (n % 2 == 0) {
        n = n / 2;
        cnt++;
      } else if (n % 3 == 0) {
        n = (2 * n) / 3;
        cnt++;
      } else if (n % 5 == 0) {
        n = (4 * n) / 5;
        cnt++;
      } else {
        cout << "-1" << endl;
        flag = 0;
        break;
      }
    }
    if (flag) cout << cnt << endl;
  }
}
