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