#include <bits/stdc++.h>
int main() {
  int amount, num, i;
  int ans;
  scanf("%d", &amount);
  for (i = 0; i < amount; i++) {
    scanf("%d", &num);
    ans = -1;
    if (num & 1) {
      if (num >= 13 || num == 9) ans = 1 + (num - 9) / 4;
    } else {
      if (num != 2) ans = num / 4;
    }
    printf("%d\n", ans);
  }
  return 0;
}
