#include <bits/stdc++.h>
using namespace std;
int a[1000][1000];
int sost[] = {4, 6, 9, 15};
int main() {
  int n, counter = 0;
  int a[100000];
  int ans[100];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    int j = 0, k = 0, counter = 0;
    int answer = 1;
    int prime = a[i];
    answer = prime / 4;
    int rem = prime % 4;
    if (rem == 1) {
      answer--;
    }
    if (rem == 3) {
      answer -= 2;
    }
    if (answer > 0) {
      if (rem == 3) answer++;
      cout << answer << "\n";
    } else
      cout << -1 << "\n";
  }
  return 0;
}
