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