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