#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  unsigned long long c;
  for (int i = 0; i < q; i++) {
    cin >> c;
    if ((c < 4) | (c % 2 != 0 & c < 13 & c != 9))
      cout << -1 << endl;
    else {
      if (c % 2 != 0)
        cout << (c - 9) / 4 + 1 << endl;
      else
        cout << c / 4 << endl;
    }
  }
}
