#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  scanf("%d", &n);
  int ans = 0;
  if (n & 1) {
    if (n < 9) {
      printf("-1\n");
      return;
    }
    n -= 9;
    ans++;
  }
  if (n % 4 == 2) {
    if (n < 6) {
      printf("-1\n");
      return;
    }
    n -= 6;
    ans++;
  }
  printf("%d\n", n / 4 + ans);
  return;
}
int main() {
  int q;
  scanf("%d", &q);
  while (q--) solve();
  return 0;
}
