#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
int Read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int t, n;
int main() {
  t = Read();
  while (t--) {
    n = Read();
    if (n % 4 == 0) {
      if (n < 4)
        printf("-1\n");
      else
        printf("%d\n", n / 4);
    } else if (n % 4 == 1) {
      if (n < 9)
        printf("-1\n");
      else
        printf("%d\n", 1 + (n - 9) / 4);
    } else if (n % 4 == 2) {
      if (n < 6)
        printf("-1\n");
      else
        printf("%d\n", 1 + (n - 6) / 4);
    } else {
      if (n < 15)
        printf("-1\n");
      else
        printf("%d\n", 2 + (n - 15) / 4);
    }
  }
  return 0;
}
