#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, j, ii, x, y, iii, cnt, cnt1, cnt2, d, mi = 0, c, a, b, k, m;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a;
    if (a < 4 || a == 5 || a == 7 || a == 11)
      cout << -1 << endl;
    else if (a % 4 == 0 || a % 4 == 2)
      cout << a / 4 << endl;
    else
      cout << (a / 4) - 1 << endl;
  }
}
