#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const int INF = (1 << 30) - 1;
int Q, N;
int main() {
  scanf("%d", &Q);
  while (Q--) {
    scanf("%d", &N);
    if (N <= 3)
      printf("-1\n");
    else {
      int num = N / 4;
      int p = N % 4;
      if (p == 0) {
        printf("%d\n", num);
      } else if (p == 1) {
        if (num == 1)
          printf("-1\n");
        else
          printf("%d\n", num - 1);
      } else if (p == 2) {
        printf("%d\n", num);
      } else {
        if (num <= 2)
          printf("-1\n");
        else
          printf("%d\n", num - 1);
      }
    }
  }
  return 0;
}
