#include <bits/stdc++.h>
int main() {
  int n, a, i, x, y, z;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &a);
    if (a < 4) {
      printf("-1\n");
      continue;
    }
    if (a % 4 == 0) {
      printf("%d\n", a / 4);
      continue;
    }
    if (a % 4 == 1) {
      x = a - 9;
      if (x % 4 == 0 && x >= 0) {
        printf("%d\n", 1 + x / 4);
      } else
        printf("-1\n");
      continue;
    }
    if (a % 4 == 2) {
      y = a - 6;
      if (y % 4 == 0 && y >= 0) {
        printf("%d\n", 1 + y / 4);
      } else
        printf("-1\n");
      continue;
    }
    if (a % 4 == 3) {
      z = a - 6 - 9;
      if (z % 4 == 0 && z >= 0) {
        printf("%d\n", 1 + 1 + z / 4);
      } else
        printf("-1\n");
      continue;
    }
  }
  return 0;
}
