#include <bits/stdc++.h>
int main() {
  int n, num;
  scanf("%d", &n);
  while (n--) {
    scanf("%d", &num);
    if (num % 4 == 0) {
      if (num / 4 >= 1)
        printf("%d\n", num / 4);
      else
        printf("-1\n");
    }
    if (num % 4 == 1) {
      if (num / 4 >= 2)
        printf("%d\n", num / 4 - 1);
      else
        printf("-1\n");
    }
    if (num % 4 == 2) {
      if (num / 4 >= 1)
        printf("%d\n", num / 4);
      else
        printf("-1\n");
    }
    if (num % 4 == 3) {
      if (num / 4 >= 3)
        printf("%d\n", num / 4 - 1);
      else
        printf("-1\n");
    }
  }
  return 0;
}
