#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int q;
  cin >> q;
  int a[q];
  for (int i = 0; i < q; i++) {
    cin >> a[i];
    if (a[i] % 4 == 0)
      cout << a[i] / 4 << endl;
    else if (a[i] % 4 == 2) {
      if (a[i] >= 6)
        cout << (a[i] - 6) / 4 + 1 << endl;
      else
        cout << "-1" << endl;
    } else if (a[i] % 4 == 1) {
      if (a[i] >= 9)
        cout << (a[i] - 9) / 4 + 1 << endl;
      else
        cout << "-1" << endl;
    } else if (a[i] % 4 == 3) {
      if (a[i] >= 15)
        cout << (a[i] - 15) / 4 + 2 << endl;
      else
        cout << "-1" << endl;
    }
  }
  return 0;
}
