#include <bits/stdc++.h>
using namespace std;
long long a[1000];
int n, k;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    while (a[i] != 1) {
      if (a[i] % 5 == 0) {
        a[i] = a[i] / 5 * 4;
        k++;
      } else if (a[i] % 3 == 0) {
        a[i] = a[i] / 3 * 2;
        k++;
      } else if (a[i] % 2 == 0) {
        a[i] /= 2;
        k++;
      } else {
        k = -1;
        break;
      }
    }
    cout << k << "\n";
    k = 0;
  }
}
