#include <bits/stdc++.h>
using namespace std;
int main() {
  int num, ans = 0;
  cin >> num;
  long long arr[1005];
  for (int i = 0; i < num; i++) {
    cin >> arr[i];
    int ans = 0;
    long long temp = arr[i];
    while (temp % 2 == 0) {
      temp /= 2;
      ans++;
    }
    while (temp % 3 == 0) {
      temp /= 3;
      ans += 2;
    }
    while (temp % 5 == 0) {
      temp /= 5;
      ans += 3;
    }
    if (temp != 1) {
      cout << "-1" << endl;
      continue;
    }
    cout << ans << endl;
  }
  return 0;
}
