#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int inf_int = INT_MAX;
const long long inf_ll = LLONG_MAX;
const double pi = acos(-1.0);
const double eps = 1e-7;
int main() {
  if ("" != "") {
    freopen(
        ""
        ".in",
        "r", stdin);
    freopen(
        ""
        ".out",
        "w", stdout);
  }
  int q;
  cin >> q;
  while (q--) {
    int n;
    cin >> n;
    if (n < 4) {
      cout << -1 << "\n";
      continue;
    }
    if (n % 4 == 0) {
      cout << n / 4 << "\n";
      continue;
    }
    if (n % 4 == 1) {
      cout << (n == 5 ? -1 : (n / 4 - 1)) << "\n";
      continue;
    }
    if (n % 4 == 2) {
      cout << n / 4 << "\n";
      continue;
    }
    if (n % 4 == 3) {
      cout << (n >= 15 ? (n / 4 - 1) : -1) << "\n";
      continue;
    }
  }
  return 0;
}
