#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int q;
  cin >> q;
  while (q--) {
    int n;
    cin >> n;
    int k = n / 4, r = n % 4;
    if (r == 0) {
      cout << k << '\n';
    } else if (r == 2) {
      if (k >= 1)
        cout << k << '\n';
      else
        cout << -1 << '\n';
    } else if (r == 1) {
      if (k >= 2)
        cout << k - 1 << '\n';
      else
        cout << -1 << '\n';
    } else {
      if (k >= 3)
        cout << k - 1 << '\n';
      else
        cout << -1 << '\n';
    }
  }
}
