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