#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  long long n[q];
  for (int i = 0; i < q; i++) {
    cin >> n[i];
  }
  long long ans[q];
  for (int i = 0; i < q; i++) {
    int div = n[i] % 4;
    if (div) {
      if (div == 1) ans[i] = (n[i] - 9) / 4 + 1;
      if (div == 2) ans[i] = (n[i] - 6) / 4 + 1;
      if (div == 3) ans[i] = (n[i] - 15) / 4 + 2;
      if (ans[i] < 1) ans[i] = -1;
      if (n[i] == 11) ans[i] = -1;
    } else
      ans[i] = n[i] / 4;
  }
  for (int i = 0; i < q; i++) {
    cout << ans[i] << "\n";
  }
}
