#include <bits/stdc++.h>
using namespace std;
const int maxn = 70005;
int main() {
  int n;
  cin >> n;
  while (n--) {
    int x;
    cin >> x;
    if (x % 4 == 0) {
      cout << x / 4 << endl;
      continue;
    }
    if (x % 4 == 1) {
      if (x < 9)
        cout << -1 << endl;
      else {
        cout << 1 + (x - 9) / 4 << endl;
      }
      continue;
    }
    if (x % 4 == 2) {
      if (x < 6)
        cout << -1 << endl;
      else
        cout << (x - 6) / 4 + 1 << endl;
      continue;
    }
    if (x <= 11)
      cout << -1 << endl;
    else
      cout << (x - 15) / 4 + 2 << endl;
  }
  return 0;
}
