#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:250000000")
using namespace std;
int dp[1001];
int a[] = {4, 6, 9, 10};
int go(int n) {
  if (n < 0) return -(int)1e9;
  if (n == 0) return 0;
  int& res = dp[n];
  if (res != -1) return res;
  res = -(int)1e9;
  for (int i = 0; i < 4; ++i) res = max(res, go(n - a[i]) + 1);
  return res;
}
int main() {
  memset(dp, -1, sizeof(dp));
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; ++i) {
    int n;
    scanf("%d", &n);
    int k = 0;
    if (n >= 900) {
      k += (n - 900) / 4;
      n -= 4 * k;
    }
    int res = go(n);
    if (res < 0)
      printf("-1\n");
    else
      printf("%d\n", res + k);
  }
  return 0;
}
