#include <bits/stdc++.h>
using namespace std;
int q;
vector<int> com = {4, 9, 6, 15};
vector<int> cnts = {1, 1, 1, 2};
int decomp(int a) {
  int c = cnts[a % 4];
  a -= com[a % 4];
  if (a < 0) return -1;
  return c + a / 4;
}
int main(void) {
  cnts.resize(com.size(), 1);
  scanf("%d", &q);
  for (int i = (0); i < ((q)); i++) {
    int n;
    scanf("%d", &n);
    printf("%d\n", decomp(n));
  }
}
