#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  scanf("%d", &q);
  while (q--) {
    int n;
    scanf("%d", &n);
    if (n < 4) {
      puts("-1");
      continue;
    }
    int m = n / 4, r = n % 4;
    if (r == 1) {
      if (m >= 2)
        m -= 1;
      else
        m = -1;
    } else if (r == 3) {
      if (n < 15)
        m = -1;
      else
        m = (n - 15) / 4 + 2;
    }
    printf("%d\n", m);
  }
  return 0;
}
