#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  if (n <= 3 || n == 11) {
    cout << -1 << "\n";
    return;
  }
  int ans = n / 4;
  if (n % 4 == 0) {
    cout << ans << "\n";
  } else {
    if (n % 4 == 1 || n % 4 == 3) {
      ans--;
    }
    if (ans == 0) {
      cout << -1 << "\n";
      return;
    }
    cout << ans << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) solve();
}
