#include <bits/stdc++.h>
int q;
int main() {
  scanf("%d", &q);
  while (q--) {
    int x;
    scanf("%d", &x);
    if (x <= 3 || x == 5 || x == 7 || x == 11)
      printf("-1");
    else {
      if (x % 4 == 0) printf("%d", x / 4);
      if (x % 4 == 1) printf("%d", (x - 9) / 4 + 1);
      if (x % 4 == 2) printf("%d", (x - 6) / 4 + 1);
      if (x % 4 == 3) printf("%d", (x - 15) / 4 + 2);
    }
    printf("\n");
  }
  return 0;
}
