#include <bits/stdc++.h>
using namespace std;
int q, n;
int main() {
  cin >> q;
  while (q--) {
    cin >> n;
    if (n < 4 || n == 5 || n == 7 || n == 11) {
      cout << -1 << endl;
      continue;
    }
    if (n % 2 == 0) {
      cout << n / 4 << endl;
      continue;
    }
    cout << (n - 5) / 4 << endl;
  }
  return 0;
}
