#include <bits/stdc++.h>
using namespace std;
int main() {
  long long tc, num, t = 1, choose;
  scanf("%lld", &tc);
  while (tc--) {
    long long cnt = 0;
    scanf("%lld", &num);
    bool ck = true;
    while (num != 1) {
      if (num % 2 == 0)
        num /= 2;
      else if (num % 3 == 0)
        num = (num / 3) * 2;
      else if (num % 5 == 0)
        num = (num / 5) * 4;
      else {
        cout << "-1" << endl;
        ck = false;
        break;
      }
      cnt++;
    }
    if (ck) cout << cnt << endl;
  }
  return 0;
}
