#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f2f1f0f;
const long long LINF = 1ll * INF * INF;
int main() {
  int Q;
  cin >> Q;
  while (Q--) {
    int n;
    scanf("%d", &n);
    if (n % 4 == 0)
      printf("%d\n", n / 4);
    else if (n % 4 == 1) {
      if (n < 9)
        printf("-1\n");
      else
        printf("%d\n", n / 4 - 1);
    } else if (n % 4 == 2) {
      if (n < 6)
        printf("-1\n");
      else
        printf("%d\n", n / 4);
    } else if (n % 4 == 3) {
      if (n < 15)
        printf("-1\n");
      else
        printf("%d\n", n / 4 - 1);
    }
  }
  return 0;
}
