#include <bits/stdc++.h>
using namespace std;
int Q, n, ans[20];
int main() {
  ans[1] = -1;
  ans[2] = -1;
  ans[3] = -1;
  ans[4] = 1;
  ans[5] = -1;
  ans[6] = 1;
  ans[7] = -1;
  ans[8] = 2;
  ans[9] = 1;
  ans[10] = 2;
  ans[11] = -1;
  ans[12] = 3;
  ans[13] = 2;
  ans[14] = 3;
  ans[15] = 2;
  scanf("%d", &Q);
  for (int i = 1; i <= Q; i++) {
    scanf("%d", &n);
    if (n <= 15)
      printf("%d\n", ans[n]);
    else {
      if (n % 4 == 0)
        printf("%d\n", n / 4);
      else if (n % 4 == 1)
        printf("%d\n", (n - 9) / 4 + 1);
      else if (n % 4 == 2)
        printf("%d\n", (n - 6) / 4 + 1);
      else if (n % 4 == 3)
        printf("%d\n", (n - 15) / 4 + 2);
    }
  }
  return 0;
}
