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