#include <bits/stdc++.h>
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  while (n--) {
    long long num;
    cin >> num;
    int res;
    if (num == 1 || num == 2 || num == 3 || num == 5 || num == 7 || num == 11) {
      res = -1;
    } else {
      if (num % 2 == 1)
        res = num / 4 - 1;
      else
        res = num / 4;
    }
    cout << res << endl;
  }
  return 0;
}
