#include <bits/stdc++.h>
using namespace std;
inline void solve() {
  int n;
  cin >> n;
  int cnt = 0;
  if (n % 2) {
    if (n < 9) {
      cout << -1 << endl;
      return;
    }
    n -= 9;
    cnt = 1;
  }
  if (n > 0 and n < 4) {
    cout << -1 << endl;
    return;
  }
  cnt += (int)(n / 4);
  if (n % 4 == 1 or n % 4 == 3)
    cout << -1 << endl;
  else
    cout << cnt << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
