#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
const int inf = 1e9 + 7;
int main() {
  int n;
  scanf("%d", &n);
  while (n--) {
    int x;
    scanf("%d", &x);
    if (x <= 3 || x == 5 || x == 7 || x == 11)
      puts("-1");
    else {
      int ans = 0, tg = x & 3;
      if (!tg) ans = max(ans, x / 4);
      if (tg == 2) ans = max(ans, 1 + (x - 6) / 4);
      if (tg == 1) ans = max(ans, 1 + (x - 9) / 4);
      if (tg == 3) ans = max(ans, 2 + (x - 15) / 4);
      printf("%d\n", ans);
    }
  }
  return 0;
}
