#include <bits/stdc++.h>
using namespace std;
template <typename tp>
inline void read(tp &x) {
  x = 0;
  char c = getchar();
  for (; c < '0' || c > '9'; c = getchar())
    ;
  for (; c >= '0' && c <= '9'; x = x * 10 + c - '0', c = getchar())
    ;
}
int n, T;
int main() {
  cin >> T;
  for (; T--;) {
    read(n);
    int ans = 0;
    if (n == 1 || n == 2 || n == 3 || n == 5 || n == 7 || n == 11)
      printf("-1\n");
    else {
      int res = n;
      if (res % 4 == 1) {
        res = res - 9;
        ans++;
      }
      if (res % 4 == 2) {
        res -= 6;
        ans++;
      }
      if (res % 4 == 3) {
        res -= 15;
        ans += 2;
      }
      if (res % 4 == 0) {
        ans += res / 4;
      }
      cout << ans << "\n";
    }
  }
}
