#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    if (n % 4 == 0) {
      cout << n / 4 << endl;
    } else if (n % 4 == 1) {
      if (n == 1 || n == 5)
        cout << "-1" << endl;
      else
        cout << n / 4 - 1 << endl;
    } else if (n % 4 == 2) {
      if (n == 2)
        cout << "-1" << endl;
      else
        cout << n / 4 << endl;
    } else {
      if (n == 3 || n == 7 || n == 11) {
        cout << "-1" << endl;
      } else
        cout << n / 4 - 1 << endl;
    }
  }
  return 0;
}
