#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const int INF = 0x3f3f3f3f;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    if (n < 10 || n == 11) {
      if (n == 4 || n == 6 || n == 9)
        printf("1\n");
      else if (n == 8)
        printf("2\n");
      else
        printf("-1\n");
    } else if (n % 2) {
      n -= 9;
      printf("%d\n", n / 4 + 1);
    } else {
      printf("%d\n", n / 4);
    }
  }
  return 0;
}
