#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    if (n == 1) {
      cout << "0" << endl;
      continue;
    }
    if (n % 2 != 0 && n % 3 != 0 && n % 5 != 0) {
      cout << "-1" << endl;
      continue;
    }
    long long int count = 0;
    while (n % 2 == 0 || n % 3 == 0 || n % 5 == 0) {
      if (n % 2 == 0) {
        count++;
        n = n / 2;
        continue;
      }
      if (n % 3 == 0) {
        count++;
        n = 2 * (n / 3);
        continue;
      }
      if (n % 5 == 0) {
        count++;
        n = 4 * (n / 5);
        continue;
      }
      if (n == 1) break;
      if (n % 2 != 0 && n % 3 != 0 && n % 5 != 0) break;
    }
    if (n == 1) cout << count << endl;
    if (n != 1) cout << "-1" << endl;
  }
}
