#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int ans[17] = {0, -1, -1, -1, 1, -1, 1, -1, 2, 1, 2, -1, 3, 2, 3, 2, 4};
  int n, nm;
  cin >> nm;
  while (nm--) {
    cin >> n;
    if (n < 16)
      cout << ans[n] << endl;
    else {
      if (n % 4 == 0)
        cout << n / 4 << endl;
      else if (n % 4 == 1)
        cout << (n - 9) / 4 + 1 << endl;
      else if (n % 4 == 2)
        cout << (n - 6) / 4 + 1 << endl;
      else if (n % 4 == 3)
        cout << (n - 15) / 4 + 2 << endl;
    }
  }
  return 0;
}
