#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int a[100000];
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  for (int i = 0; i < n; i++) {
    if (a[i] < 4) {
      printf("-1\n");
      continue;
    }
    if (a[i] % 2 == 0) {
      printf("%d\n", a[i] / 4);
      continue;
    }
    if (a[i] < 9) {
      printf("-1\n");
      continue;
    }
    if (a[i] == 11) {
      printf("-1\n");
      continue;
    }
    printf("%d\n", 1 + (a[i] - 9) / 4);
  }
  return 0;
}
