#include <bits/stdc++.h>
using namespace std;
int solve(int num) {
  if (num == 1 || num == 2 || num == 3 || num == 5 || num == 7 || num == 11)
    return -1;
  int t = num / 4 - num % 2;
  return t ? t : -1;
}
int main() {
  int n, num;
  while (~scanf("%d", &n)) {
    for (int i = 0; i < n; i++) {
      scanf("%d", &num);
      printf("%d\n", solve(num));
    }
  }
  return 0;
}
