#include <bits/stdc++.h>
using namespace std;
template <typename T, typename T1>
T amax(T &a, T1 b) {
  if (b > a) a = b;
  return a;
}
template <typename T, typename T1>
T amin(T &a, T1 b) {
  if (b < a) a = b;
  return a;
}
const int32_t mod = 1e9 + 7;
const long long INF = 1e18;
const long long N = 1e5 + 5, M = 103;
void solve() {
  long long n;
  cin >> n;
  if (n < 4) {
    cout << "-1\n";
    return;
  }
  if (n % 2 == 0) {
    cout << n / 4 << "\n";
    return;
  }
  n -= 9;
  if (n > 3 || n == 0)
    cout << n / 4 + 1 << "\n";
  else
    cout << "-1\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) solve();
  return 0;
}
