#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n, i, s = 0, first = 0;
    cin >> n;
    if (n % 2 && n >= 9) {
      s++;
      n -= 9;
    }
    if (n % 4 && n >= 6) {
      s++;
      n -= 6;
    }
    if (n % 4 == 0) {
      s += n / 4;
      n = 0;
      first = 1;
    }
    if (!first || n)
      cout << "-1\n";
    else
      cout << s << "\n";
  }
}
