#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, i, q, n;
  cin >> q;
  for (t = 1; t <= q; t++) {
    cin >> n;
    if (n == 1)
      cout << "-1" << endl;
    else if (n == 2)
      cout << "-1" << endl;
    else if (n == 3)
      cout << "-1" << endl;
    else if (n == 5)
      cout << "-1" << endl;
    else if (n == 7)
      cout << "-1" << endl;
    else if (n == 11)
      cout << "-1" << endl;
    else if (n % 4 == 0)
      cout << n / 4 << endl;
    else if (n % 4 == 1)
      cout << (n - 5) / 4 << endl;
    else if (n % 4 == 2)
      cout << (n - 2) / 4 << endl;
    else
      cout << (n - 7) / 4 << endl;
  }
}
