#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 5;
const long long MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
int main() {
  int T, x;
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &x);
    if (x % 4 == 0) {
      if (x < 4)
        printf("-1\n");
      else
        printf("%d\n", x / 4);
    } else if (x % 4 == 1) {
      if (x < 9)
        printf("-1\n");
      else
        printf("%d\n", (x - 9) / 4 + 1);
    } else if (x % 4 == 2) {
      if (x < 6)
        printf("-1\n");
      else
        printf("%d\n", (x - 6) / 4 + 1);
    } else {
      if (x < 15)
        printf("-1\n");
      else
        printf("%d\n", (x - 15) / 4 + 2);
    }
  }
  return 0;
}
