#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long double pi = acos(-1);
const int MOD = 1e9 + 7;
const long long int LINF = 0x3f3f3f3f3f3f3f3f;
int ans(int n) {
  if (n < 4) return -1;
  if (n == 5) return -1;
  if (n == 7) return -1;
  if (n == 11) return -1;
  if (n % 2 == 0)
    return n / 4;
  else
    return (n - 9) / 4 + 1;
}
int main() {
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int n;
    scanf("%d", &n);
    printf("%d\n", ans(n));
  }
  return 0;
}
