#include <bits/stdc++.h>
using namespace std;
const int N = 1;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  while (n--) {
    int t, ans = 0;
    cin >> t;
    if (t < 4 || t == 5 || t == 7 || t == 11)
      cout << -1 << endl;
    else {
      if (t % 2) {
        ans++;
        t -= 9;
      }
      cout << ans + t / 4 << endl;
      ;
    }
  }
  return 0;
}
