#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    if (n == 2)
      cout << -1 << '\n';
    else if (n <= 11 && n & 1 && n != 9)
      cout << -1 << '\n';
    else if (n == 9)
      cout << 1 << '\n';
    else if (n & 1)
      cout << (n - 9) / 4 + 1 << '\n';
    else
      cout << n / 4 << '\n';
  }
}
