#include <bits/stdc++.h>
using namespace std;
int q, n;
void answer(int n) {
  if (n == 9) {
    cout << 1 << "\n";
    return;
  }
  if (n % 2 == 0) {
    int p = n / 2;
    if (p > 1) {
      cout << p / 2 << "\n";
      return;
    } else {
      cout << -1 << "\n";
      return;
    }
  } else if (n > 11) {
    n -= 9;
    if (n % 2 == 0) {
      int p = n / 2;
      if (p > 1) {
        cout << 1 + p / 2 << "\n";
        return;
      } else {
        cout << -1 << "\n";
        return;
      }
    }
  }
  cout << -1 << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> n;
    answer(n);
  }
}
