#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long ans = 0;
    while (n % 2 == 0) {
      n /= 2;
      ans++;
    }
    while (n % 3 == 0) {
      n /= 3;
      ans += 2;
    }
    while (n % 5 == 0) {
      n /= 5;
      ans += 3;
    }
    while (n % 2 == 0) {
      n /= 2;
      ans++;
    }
    if (n == 1)
      cout << ans << endl;
    else
      cout << "-1" << endl;
  }
}
