#include <bits/stdc++.h>
using namespace std;
template <class T>
T GCD(T a, T b) {
  return (b != 0 ? GCD<T>(b, a % b) : a);
}
template <class T>
T LCM(T a, T b) {
  return ((a * b) / GCD<T>(a, b));
}
int main() {
  int q, n;
  cin >> q;
  int cnt, b;
  for (int i = 0; i < q; i++) {
    cin >> n;
    b = n % 4;
    cnt = n / 4;
    if (n < 4)
      cnt = -1;
    else if (b == 1) {
      if (cnt >= 2)
        cnt--;
      else
        cnt = -1;
    } else if (b == 3) {
      if (cnt >= 3)
        cnt--;
      else
        cnt = -1;
    }
    cout << cnt << endl;
  }
  return 0;
}
