#include <bits/stdc++.h>
using namespace std;
long long int solucion(long long int n) {
  long long int resp = 0;
  switch (n % 4LL) {
    case 0:
      resp = n / 4LL;
      break;
    case 1:
      if (n >= 9) {
        n -= 9;
        resp = 1;
        resp += n / 4LL;
      } else
        resp = -1;
      break;
    case 2:
      if (n >= 6) {
        n -= 6;
        resp = 1;
        resp += n / 4LL;
      } else
        resp = -1;
      break;
    case 3:
      if (n >= 15) {
        n -= 15;
        resp = 2;
        resp += n / 4LL;
      } else
        resp = -1;
      break;
  }
  return resp;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int Q;
  cin >> Q;
  long long int n;
  while (Q--) {
    cin >> n;
    cout << solucion(n) << "\n";
  }
  return 0;
}
