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