#include <bits/stdc++.h>
int main() {
  int q;
  scanf("%d", &q);
  for (; q--;) {
    int n, ans = 0;
    scanf("%d", &n);
    if (n % 2 == 1) {
      n -= 9;
      ++ans;
      if (n < 0) {
        printf("%d\n", -1);
        continue;
      }
    }
    if (n % 4 == 2) {
      n -= 6;
      ++ans;
      if (n < 0) {
        printf("%d\n", -1);
        continue;
      }
    }
    printf("%d\n", ans + n / 4);
  }
  return 0;
}
