#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007LL;
long long base = 10000007;
long long large = 1000000000000000000LL;
bitset<10000000> vis;
vector<int> primes;
void sieve(long long n) {
  vis.set();
  vis[0] = 0;
  vis[1] = 0;
  for (long long i = 2; i <= n; i++) {
    if (vis[i]) {
      for (long long j = i * i; j <= n; j += i) {
        vis[j] = 0;
      }
      primes.push_back((int)i);
    }
  }
}
int main() {
  sieve(1000000);
  int q;
  cin >> q;
  while (q--) {
    int x;
    cin >> x;
    int temp = x / 4;
    if (x % 4 > 0) {
      if (x % 4 == 1) {
        temp -= 1;
      }
      if (x % 4 == 3) {
        if (x == 7 || x == 11) {
          cout << -1 << endl;
          continue;
        }
        temp -= 1;
      }
    }
    if (temp <= 0) temp = -1;
    cout << temp << endl;
  }
  return 0;
}
