#include <bits/stdc++.h>
using namespace std;
int IN() {
  int c, f, x;
  while (!isdigit(c = getchar()) && c != '-')
    ;
  c == '-' ? (f = 1, x = 0) : (f = 0, x = c - '0');
  while (isdigit(c = getchar())) x = (x << 1) + (x << 3) + c - '0';
  return !f ? x : -x;
}
int main() {
  for (int q = IN(); q--;) {
    int n = IN();
    if (n % 4 == 0) {
      printf("%d\n", n / 4);
    } else if (n % 4 == 1) {
      if (n <= 5)
        puts("-1");
      else
        printf("%d\n", (n - 5) / 4);
    } else if (n % 4 == 2) {
      if (n <= 2)
        puts("-1");
      else
        printf("%d\n", (n - 2) / 4);
    } else if (n % 4 == 3) {
      if (n <= 11)
        puts("-1");
      else
        printf("%d\n", (n - 7) / 4);
    }
  }
}
