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