#include <bits/stdc++.h>
using namespace std;
const int table[] = {0, -1, -1, -1, 1, -1, 1, -1, 2, 1, 2, -1, 3, 2, 3, 2, 4};
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int n;
    scanf("%d", &n);
    int ans = n / 4, mod = n % 4;
    if (mod == 1)
      --ans;
    else if (mod == 3)
      --ans;
    printf("%d\n", n <= 16 ? table[n] : ans);
  }
  return 0;
}
