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