#include <bits/stdc++.h>
using namespace std;
unsigned long long q, n, ans;
int main() {
  cin >> q;
  while (q--) {
    cin >> n;
    ans = 0;
    while (n > 1) {
      if (n % 2 == 0)
        n /= 2;
      else if (n % 3 == 0)
        n /= 3, n *= 2;
      else if (n % 5 == 0)
        n /= 5, n *= 4;
      else {
        ans = -1;
        break;
      }
      ++ans;
    }
    if (ans == 18446744073709551615)
      cout << -1 << endl;
    else
      cout << ans << endl;
  }
  return 0;
}
