#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
int main() {
  long long int i, j, k, l, m, n, p, q, x, y, z, a, b, r;
  scanf("%lld", &q);
  while (q--) {
    scanf("%lld", &n);
    if (n == 11)
      printf("-1\n");
    else if (n >= 4 && n % 2 == 0)
      printf("%lld\n", n / 4);
    else if (n >= 9)
      printf("%lld\n", 1 + (n - 9) / 4);
    else
      printf("-1\n");
  }
  return 0;
}
