#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_gt = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
using pq_lt = priority_queue<T, vector<T>, less<T>>;
vector<int> compo;
int ans[1000];
bool isPrime(int x) {
  for (int i = 2; i <= sqrt(x); ++i) {
    if (x % i == 0) {
      return false;
    }
  }
  return true;
}
void solve(int x) {
  for (int i = 0; i < compo.size() && compo[i] <= x; ++i) {
    if (ans[x - compo[i]] != -1) ans[x] = max(ans[x], 1 + ans[x - compo[i]]);
  }
}
int main() {
  ios::sync_with_stdio(false);
  for (int i = 4; i < 1000; ++i) {
    if (!isPrime(i)) {
      compo.push_back(i);
    }
  }
  for (int i = 1; i < 1000; i++) {
    ans[i] = -1;
  }
  for (int i = 1; i < 1000; ++i) {
    solve(i);
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int t;
    cin >> t;
    if (t < 1000) {
      cout << ans[t] << endl;
    } else {
      int temp = (t - 996) / 4;
      cout << temp + ans[t - 4 * temp] << endl;
      ;
    }
  }
}
