#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  scanf("%d", &q);
  while (q--) {
    int n;
    scanf("%d", &n);
    bool flag = 0;
    if (n <= 3 || n == 5 || n == 7 || n == 11)
      ;
    else
      flag = 1;
    int ans;
    if (!flag)
      ans = -1;
    else {
      if (n % 4 == 0)
        ans = n / 4;
      else if (n % 4 == 1)
        ans = (n - 9) / 4 + 1;
      else if (n % 4 == 2)
        ans = (n - 6) / 4 + 1;
      else
        ans = (n - 6 - 9) / 4 + 2;
    }
    printf("%d\n", ans);
  }
  return 0;
}
