#include <bits/stdc++.h>
using namespace std;
long long int dp[1000007] = {0};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n;
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> n;
    if (n <= 3 || n == 5 || n == 7 || n == 11) {
      cout << -1 << '\n';
      continue;
    }
    if (n < 1000000) {
      if (dp[n] != 0) {
        cout << dp[n] << '\n';
        continue;
      }
    }
    int ans = n / 4;
    if (n & 1) {
      ans--;
    }
    if (n < 1000000) {
      dp[n] = ans;
    }
    cout << ans << '\n';
  }
  return 0;
}
