#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    if (n % 2 == 0) {
      if (n < 4)
        cout << -1 << "\n";
      else
        cout << n / 4 << "\n";
    } else if (n == 9)
      cout << 1 << "\n";
    else {
      if (n < 13)
        cout << -1 << "\n";
      else
        cout << (n - 9) / 4 + 1 << "\n";
    }
  }
}
