#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
using ll = long long;
using ld = long double;
template <typename t>
using V = vector<t>;
template <typename t, size_t s>
using A = array<t, s>;
void print() { cout << '\n'; }
template <typename t, typename... v>
void print(const t& a, const v&... b) {
  cout << a << (sizeof...(b) ? " " : "");
  print(b...);
}
template <typename t>
void print_range(t a, const t& b) {
  while (a != b) cout << (*a++) << ' ';
  cout << '\n';
}
constexpr int qax = 1e5, nax = 1e9;
int q;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int n;
    cin >> n;
    if (n < 4 or n == 5 or n == 7 or ((n % 4 == 3) and n < 15)) {
      print(-1);
      continue;
    }
    if ((n % 4) == 1) n -= 4;
    if ((n % 4) == 3) n -= 4;
    print(n / 4);
  }
}
