#include <bits/stdc++.h>
using namespace std;
long long q, n;
int main() {
  cin >> q;
  while (q--) {
    cin >> n;
    if (n % 4 == 0) {
      if (n >= 0)
        cout << n / 4 << "\n";
      else
        cout << -1 << "\n";
    } else if (n % 4 == 1) {
      if (n - 9 >= 0)
        cout << 1 + (n - 9) / 4 << "\n";
      else
        cout << -1 << "\n";
    } else if (n % 4 == 2) {
      if (n - 6 >= 0)
        cout << 1 + (n - 6) / 4 << "\n";
      else
        cout << -1 << "\n";
    } else {
      if (n - 15 >= 0)
        cout << 2 + (n - 15) / 4 << "\n";
      else
        cout << -1 << "\n";
    }
  }
  return 0;
}
