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