#include <bits/stdc++.h>
using namespace std;
int maxs(int n) {
  if (n < 12) {
    switch (n) {
      case 1:
      case 2:
      case 3:
      case 5:
      case 7:
      case 11:
        return -1;
      case 4:
      case 6:
      case 9:
        return 1;
      case 8:
      case 10:
        return 2;
    }
  }
  if (n % 4 == 0 || n % 4 == 2) return (n / 4);
  return ((n / 4) - 1);
}
int main() {
  ios::sync_with_stdio(false);
  int q;
  cin >> q;
  int n;
  while (q--) {
    cin >> n;
    cout << maxs(n) << "\n";
  }
  return 0;
}
