#include <bits/stdc++.h>
using namespace std;
int i, j, x, y, z, m, n, k, l, r, f, mi = 1e9;
int a[200];
bool pr(int n) {
  for (int i = 2; i * i <= n; i++)
    if (n % i == 0) return true;
  return false;
}
int main() {
  scanf("%d", &n);
  a[1] = a[2] = a[3] = -1;
  a[4] = 1;
  for (int i = 5; i < 100; i++) {
    int t = -1;
    if (pr(i)) t = 1;
    for (int j = 4; j <= i / 2; j++)
      if (pr(j) && pr(i - j)) t = max(t, a[j] + a[i - j]);
    a[i] = t;
  }
  while (n--) {
    scanf("%d", &m);
    int ans;
    if (m < 20)
      ans = a[m];
    else {
      ans = m / 4;
      m = m % 4;
      if (m == 1) ans--;
      if (m == 3) ans--;
    }
    printf("%d\n", ans);
  }
}
