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