#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int q;
  cin >> q;
  while (q--) {
    long long int n;
    cin >> n;
    if (n < 4)
      cout << -1 << "\n";
    else if (n % 4 == 0)
      cout << n / 4 << "\n";
    else if (n % 4 == 1) {
      if (n / 4 >= 2)
        cout << (n / 4) - 1 << "\n";
      else
        cout << -1 << "\n";
    } else if (n % 4 == 2) {
      if (n / 4 >= 1) cout << n / 4 << "\n";
    } else if (n % 4 == 3) {
      if (n / 4 >= 3)
        cout << (n / 4) - 1 << "\n";
      else
        cout << -1 << "\n";
    }
  }
  return 0;
}
