#include <bits/stdc++.h>
using namespace std;
int prime[100001] = {0};
void p() {
  for (int i = 2; i <= 100000; i++)
    if (!prime[i])
      for (int j = 2 * i; j <= 100000; j += i) prime[j] = 1;
}
int main() {
  p();
  int n;
  cin >> n;
  while (n--) {
    long long q;
    cin >> q;
    long long a = q / 4;
    int x = q % 4;
    if (a == 0)
      cout << -1 << endl;
    else if (x == 0 || x == 2)
      cout << a << endl;
    else if (x == 1 || x == 3) {
      if (a - 1 == 0)
        cout << -1 << endl;
      else if (a - 1 == 1 && prime[q] == 0)
        cout << -1 << endl;
      else
        cout << a - 1 << endl;
    }
  }
  return 0;
}
