#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 5;
int add(int x, int y) {
  x += y;
  if (x >= mod) x -= mod;
  return x;
}
int mul(int x, int y) {
  long long z = 1LL * x * y;
  return z - z / mod * mod;
}
int main() {
  int q, x, a, b;
  scanf("%d", &q);
  while (q--) {
    scanf("%d", &x);
    a = x / 4;
    b = x % 4;
    if (b == 0)
      printf("%d\n", a);
    else if (b == 2) {
      if (a >= 1)
        printf("%d\n", a);
      else
        printf("-1\n");
    } else if (b == 1) {
      if (a >= 2)
        printf("%d\n", a - 1);
      else
        printf("-1\n");
    } else {
      if (a >= 3)
        printf("%d\n", a - 1);
      else
        printf("-1\n");
    }
  }
  return 0;
}
