#include <bits/stdc++.h>
using namespace std;
int solve() {
  int N;
  cin >> N;
  if (N % 2) {
    N -= 9;
    if (N < 0 || N == 2) return -1;
    return 1 + N / 4;
  } else {
    if (N < 4) return -1;
    return N / 4;
  }
}
int main() {
  int Q;
  cin >> Q;
  while (Q--) cout << solve() << endl;
  return 0;
}
