#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
int n, a, res;
int count(int x) {
  if (x == 0) return 0;
  if (x < 4) return -INF;
  if (x % 2 == 1) return 1 + count(x - 9);
  return x / 4;
}
int main() {
  scanf("%d", &n);
  while (n--) {
    scanf("%d", &a);
    res = count(a);
    if (res < 0)
      printf("-1\n");
    else
      printf("%d\n", res);
  }
  return 0;
}
