#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k;
  int q, n;
  scanf("%d", &q);
  while (q--) {
    scanf("%d", &n);
    if (n == 2 || (n % 2 != 0 && n <= 11 && n != 9))
      printf("-1\n");
    else {
      int ans = 0;
      if (n % 2) {
        n -= 9;
        ans++;
      }
      ans += n / 4;
      printf("%d\n", ans);
    }
  }
  return 0;
}
