#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  int a[t];
  for (int k = 0; k < t; k++) {
    long long int n;
    cin >> n;
    int j = 0, c = 0;
    while (n % 5 == 0) {
      c++;
      j = j + 2;
      n = n / 5;
    }
    while (n % 3 == 0) {
      c++;
      j++;
      n = n / 3;
    }
    while (n % 2 == 0) {
      j++;
      n = n / 2;
    }
    if (n != 1)
      a[k] = -1;
    else {
      a[k] = j + c;
    }
  }
  for (int k = 0; k < t; k++) cout << a[k] << endl;
}
