#include <bits/stdc++.h>
using namespace std;
const double PI =
    3.141592653589793238462643383279502884197169399375105820974944;
int main() {
  int q;
  cin >> q;
  for (int t = 0; t < q; t++) {
    int n;
    cin >> n;
    if (n % 2 == 0) {
      if (n == 2)
        cout << -1;
      else
        cout << n / 4;
    } else {
      if (n == 1 || n == 3 || n == 5 || n == 7 || n == 11)
        cout << -1;
      else
        cout << 1 + (n - 9) / 4;
    }
    cout << endl;
  }
}
