#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int flag = 0, cnt = 0;
    unsigned long long int n;
    cin >> n;
    while (n > 1) {
      if (n % 2 == 0) {
        n /= 2;
        cnt++;
      } else if (n % 3 == 0) {
        n = 2 * n / 3;
        cnt++;
      } else if (n % 5 == 0) {
        n = 4 * n / 5;
        cnt++;
      } else if (n == 1) {
        break;
      } else {
        flag = 1;
        break;
      }
    }
    if (flag == 1) {
      cout << "-1" << endl;
    } else {
      cout << cnt << endl;
    }
  }
}
