#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, T;
  cin >> T;
  while (T--) {
    cin >> n;
    if (n <= 3 || n == 5 || n == 7 || n == 11)
      cout << "-1\n";
    else if (n % 2 == 0)
      cout << n / 4 << '\n';
    else
      cout << (n - 9) / 4 + 1 << '\n';
  }
  return 0;
}
