#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k4 = 0, kk;
  cin >> kk;
  for (int i = 1; i <= kk; i++) {
    cin >> n;
    k4 = n / 4;
    if (n % 4 == 0) cout << k4 << endl;
    if (n % 4 == 1) {
      if (k4 >= 2)
        cout << k4 - 1 << endl;
      else
        cout << -1 << endl;
    }
    if (n % 4 == 2) {
      if (k4 >= 1)
        cout << k4 << endl;
      else
        cout << -1 << endl;
    }
    if (n % 4 == 3) {
      if (k4 >= 3) {
        cout << k4 - 1 << endl;
      } else
        cout << -1 << endl;
    }
  }
}
