#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  long long int n;
  long long int t;
  cin >> t;
  int count = 0;
  while (t != 0) {
    long long int n;
    cin >> n;
    int count = 0;
    bool an = false;
    bool z = false;
    bool np = false;
    while (n >= 1) {
      if (n == 1) {
        an = true;
        break;
      } else if (n == 0) {
        z = true;
        break;
      } else {
        if (n % 2 == 0) {
          n = n / 2;
          count++;
        } else if (n % 3 == 0) {
          n = 2 * (n / 3);
          count++;
        } else if (n % 5 == 0) {
          n = 4 * (n / 5);
          count++;
        } else {
          np = true;
          break;
        }
      }
    }
    if (an == true) {
      cout << count << endl;
    } else if (z == true) {
      cout << -1 << endl;
    } else if (np == true) {
      cout << -1 << endl;
    }
    t--;
  }
  return 0;
}
