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