#include <bits/stdc++.h>
using namespace std;
int q;
long long soal;
int main() {
  cin >> q;
  for (int i = 1; i <= q; i++) {
    cin >> soal;
    bool tes = false;
    int counter = 0;
    while (soal % 2 == 0 || soal % 3 == 0 || soal % 5 == 0) {
      while (soal % 2 == 0) {
        soal = soal / 2;
        counter++;
      }
      while (soal % 3 == 0) {
        soal = soal * 2 / 3;
        counter++;
      }
      while (soal % 5 == 0) {
        soal = soal * 4 / 5;
        counter++;
      }
    }
    if (soal > 1) {
      cout << "-1" << endl;
    } else
      cout << counter << endl;
  }
}
