#include <bits/stdc++.h>
long long readInt() {
  long long ans = 0;
  int c;
  while (!isdigit(c = getchar()))
    ;
  do ans = ans * 10 + c - '0';
  while (isdigit(c = getchar()));
  return ans;
}
void putInt(long long n, char c) {
  if (n < 0) putchar('-'), n = -n;
  static int p[100];
  int i = 0;
  while (!i || n) p[i++] = n % 10, n /= 10;
  while (i) putchar(p[--i] + '0');
  putchar(c);
}
int main() {
  int q = readInt();
  while (q--) {
    int n = readInt(), ans = 0;
    if (n < 4 || n == 5 || n == 7 || n == 11) {
      putInt(-1, '\n');
      continue;
    }
    if (n & 1) n -= 9, ++ans;
    if (n & 3) n -= 6, ++ans;
    ans += n / 4;
    putInt(ans, '\n');
  }
  return 0;
}
