#include <bits/stdc++.h>
using namespace std;
bool primo(long long a) {
  for (int i = 2; i * i <= a; i++)
    if (a % i == 0) return false;
  return true;
}
int main() {
  int m;
  long long n;
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> n;
    long long d = n / 4;
    long long r = n % 4;
    if (r == 0) {
      cout << d << "\n";
    } else if (r == 1) {
      if (d < 2)
        cout << -1 << "\n";
      else
        cout << d - 1 << "\n";
    } else if (r == 2) {
      if (d < 1)
        cout << -1 << "\n";
      else
        cout << d << "\n";
    } else {
      if (d < 3)
        cout << -1 << "\n";
      else
        cout << d - 1 << "\n";
    }
  }
  return 0;
}
