#include <bits/stdc++.h>
using namespace std;
int main() {
  long long q;
  cin >> q;
  while (q--) {
    long long n;
    cin >> n;
    long long cnt = 0;
    while (n % 3 == 0 || n % 5 == 0) {
      cnt++;
      if (n % 3 == 0) {
        n = n * 2 / 3;
        continue;
      } else if (n % 5 == 0) {
        n = n * 4 / 5;
        continue;
      }
    }
    if (n == 1)
      puts("0");
    else if (n % 2 != 0 || (log2(n) != (long long)log2(n)))
      puts("-1");
    else
      cout << cnt + log2(n) << "\n";
  }
}
