#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)1e18 + 5;
namespace SOLVE {
void main() {
  long long n = 20;
  vector<long long> dp(n, -1);
  vector<long long> A = {4, 6, 9};
  dp[0] = 0;
  for (long long i = 1; i < n; i++) {
    for (long long a : A) {
      if (i - a >= 0 && dp[i - a] != -1) {
        dp[i] = max(dp[i], dp[i - a] + 1);
      }
    }
  }
  long long q;
  cin >> q;
  for (long long i = 0; i < q; i++) {
    long long x, ans;
    cin >> x;
    if (x >= 16) {
      ans = dp[16 + (x % 4)] + (x - 16) / 4;
    } else {
      ans = dp[x];
    }
    ans = ans >= inf ? -1 : ans;
    cout << ans << endl;
  }
}
}  // namespace SOLVE
signed main() {
  int t;
  t = 1;
  while (t--) {
    SOLVE::main();
  }
  return 0;
}
