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