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