#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int i, q, n, an;
  int a[16];
  for (i = 0; i < 16; i++) a[i] = -1;
  a[4] = 1;
  a[6] = 1;
  a[8] = 2;
  a[9] = 1;
  a[10] = 2;
  a[12] = 3;
  a[13] = 2;
  a[14] = 3;
  a[15] = 2;
  cin >> q;
  while (q--) {
    cin >> n;
    if (n < 16) {
      cout << a[n];
    } else {
      an = 0;
      an = n / 4;
      an -= 3;
      n %= 4;
      n += 12;
      cout << (an + a[n]);
    }
    cout << endl;
  }
  return 0;
}
