#include <bits/stdc++.h>
using namespace std;
int t;
int x;
int main() {
  cin >> t;
  for (int i = 1; i <= t; i++) {
    cin >> x;
    if (x < 4)
      cout << -1 << endl;
    else if (x % 2 == 0)
      cout << x / 4 << endl;
    else if (x > 11)
      cout << x / 4 - 1 << endl;
    else if (x < 9)
      cout << -1 << endl;
    else if (x == 9)
      cout << 1 << endl;
    else
      cout << -1 << endl;
  }
  return 0;
}
