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