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