#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, n, a[100000];
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 1 || a[i] == 2 || a[i] == 3 || a[i] == 5 || a[i] == 7 ||
        a[i] == 11)
      cout << "-1" << endl;
    else if (a[i] == 4 || a[i] == 6 || a[i] == 9) {
      cout << "1" << endl;
    } else {
      if (a[i] % 4 == 0) cout << a[i] / 4 << endl;
      if (a[i] % 4 == 1) cout << a[i] / 4 - 1 << endl;
      if (a[i] % 4 == 2) cout << a[i] / 4 << endl;
      if (a[i] % 4 == 3) cout << a[i] / 4 - 1 << endl;
    }
  }
}
