#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b, long long m) {
  long long x = 1 % m;
  a %= m;
  while (b) {
    if ((1 & b)) x = x * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return x;
}
int ans[15];
int main() {
  int q;
  scanf("%d", &q);
  int no = -1;
  ans[1] = ans[2] = ans[3] = ans[5] = ans[7] = -1;
  ans[4] = ans[6] = ans[9] = 1;
  ans[10] = ans[8] = 2;
  ans[11] = -1;
  while (q--) {
    int n;
    scanf("%d", &n);
    if (n < 12) {
      printf("%d\n", ans[n]);
      continue;
    }
    int ans = 0;
    if (n % 2) n -= 9, ++ans;
    if (n % 4 == 0)
      ans += n / 4;
    else
      n -= 6, ++ans, ans += n / 4;
    printf("%d\n", ans);
  }
}
