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