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