#include <bits/stdc++.h>
using i32 = int32_t;
using i64 = int64_t;
int main() {
  i32 q = 0;
  std::cin >> q;
  for (size_t i = 0; i < q; ++i) {
    i64 x = 0;
    std::cin >> x;
    i32 tmp = x;
    i32 cnt = 0;
    while (true) {
      if (x == 1) {
        std::cout << cnt << '\n';
        break;
      } else if (x % 5 == 0) {
        x /= 5;
        x *= 4;
        ++cnt;
      } else if (x % 3 == 0) {
        x /= 3;
        x *= 2;
        ++cnt;
      } else if (x % 2 == 0) {
        x /= 2;
        ++cnt;
      } else {
        std::cout << -1 << '\n';
        break;
      }
    }
  }
  return 0;
}
