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