#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0);
  int q;
  long long int n, temp;
  cin >> q;
  while (q--) {
    cin >> n;
    temp = n;
    int flag = 0;
    long long int count = 0;
    while (temp > 1) {
      if (temp % 2 == 0)
        temp = temp / 2;
      else if (temp % 3 == 0)
        temp = 2 * temp / 3;
      else if (temp % 5 == 0)
        temp = 4 * temp / 5;
      else {
        flag = 1;
        break;
      }
      count++;
    }
    if (flag == 1)
      cout << "-1\n";
    else
      cout << count << "\n";
  }
  return 0;
}
