#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long a;
  for (int i = 1; i <= n; ++i) {
    cin >> a;
    int cnt = 0, cnt2 = 0, cnt3 = 0;
    while (a % 2 == 0) {
      a /= 2;
      cnt++;
    }
    while (a % 3 == 0) {
      a /= 3;
      cnt2++;
    }
    while (a % 5 == 0) {
      a /= 5;
      cnt3++;
    }
    if (a != 1) {
      cout << -1 << endl;
    } else {
      cout << cnt + cnt2 * 2 + cnt3 * 3 << endl;
    }
  }
  return 0;
}
