#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    long long int n;
    cin >> n;
    long long int m = n, t1 = 0, t2 = 0, t3 = 0;
    while (m % 2 == 0) {
      t1++;
      m = m / 2;
    }
    while (m % 3 == 0) {
      t2++;
      m = m / 3;
    }
    while (m % 5 == 0) {
      t3++;
      m = m / 5;
    }
    if (m == 1)
      cout << t1 + t2 * 2 + t3 * 3 << endl;
    else
      cout << -1 << endl;
  }
}
