#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
  int n;
  cin >> n;
  while (n--) {
    int b, k;
    cin >> b;
    if (b % 4 == 0)
      k = b / 4;
    else if (b % 4 == 1) {
      if (b / 4 >= 2)
        k = b / 4 - 1;
      else
        k = -1;
    } else if (b % 4 == 2) {
      if (b / 4 >= 1)
        k = b / 4;
      else
        k = -1;
    } else if (b % 4 == 3) {
      if (b / 4 >= 3)
        k = b / 4 - 1;
      else
        k = -1;
    }
    cout << k << endl;
  }
  return 0;
}
