#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    if (n % 2 == 0) {
      int t = n / 4;
      cout << (t == 0 ? -1 : t) << endl;
    } else {
      if (n < 9)
        cout << -1 << endl;
      else if (n == 9)
        cout << 1 << endl;
      else {
        int t = (n - 9) / 4;
        if (t == 0)
          cout << -1 << endl;
        else
          cout << t + 1 << endl;
      }
    }
  }
  return 0;
}
