#include <bits/stdc++.h>
int main() {
  int q;
  long n[100005];
  long fours;
  int i;
  long rem;
  long out;
  scanf("%d", &q);
  for (i = 0; i < q; i++) scanf("%d", &n[i]);
  for (i = 0; i < q; i++) {
    if (n[i] >= 12) {
      fours = n[i] / 4;
      rem = n[i] - 4 * fours;
      if (rem == 0) out = fours;
      if (rem == 1) out = fours - 1;
      if (rem == 2) out = fours;
      if (rem == 3) out = fours - 1;
    }
    if ((n[i] == 1) | (n[i] == 2) | (n[i] == 3) | (n[i] == 7) | (n[i] == 5) |
        (n[i] == 11))
      out = -1;
    if ((n[i] == 4) | (n[i] == 6) | (n[i] == 9)) out = 1;
    if ((n[i] == 8) | (n[i] == 10)) out = 2;
    printf("%ld \n", out);
  }
  return 0;
}
