#include <bits/stdc++.h>
using namespace std;
int main() {
  int test;
  cin >> test;
  for (int i = 1; i <= test; i++) {
    long long n;
    int cnt = 0;
    cin >> n;
    while (n % 2 == 0) {
      n = n / 2;
      cnt++;
    }
    while (n % 3 == 0) {
      n = n / 3;
      cnt = cnt + 2;
    }
    while (n % 5 == 0) {
      n = n / 5;
      cnt = cnt + 3;
    }
    if (n == 1) {
      cout << cnt << "\n";
    } else {
      cout << -1 << "\n";
    }
  }
  return 0;
}
