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