#include <bits/stdc++.h>
using namespace std;
int q;
int k;
int main() {
  cin >> q;
  for (int i = 0; i < q; ++i) {
    cin >> k;
    if (k % 4 == 0) cout << (k / 4 <= 0 ? -1 : k / 4);
    if (k % 4 == 1) cout << (k / 4 - 1 <= 0 ? -1 : k / 4 - 1);
    if (k % 4 == 2) cout << (k / 4 <= 0 ? -1 : k / 4);
    if (k % 4 == 3) cout << (k / 4 - 2 <= 0 ? -1 : k / 4 - 1);
    cout << endl;
  }
}
