#include <bits/stdc++.h>
using namespace std;
int hg;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int q;
  cin >> q;
  while (q--) {
    int n;
    cin >> n;
    int a[3] = {4, 6, 9};
    vector<int> ans(17);
    for (int i = 1; i <= 15; i++) {
      ans[i] = -1;
      for (int j = 0; j < 3; j++) {
        if (i - a[j] >= 0 && ans[i - a[j]] != -1)
          ans[i] = max(ans[i], ans[i - a[j]] + 1);
      }
    }
    if (n < 16) {
      cout << ans[n] << '\n';
    } else {
      int t = (n - 16) / 4 + 1;
      cout << t + ans[n - t * 4] << '\n';
    }
  }
  return 0;
}
