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