#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long p[12] = {0};
  p[1] = 1;
  p[2] = 1;
  p[3] = 1;
  p[5] = 1;
  p[7] = 1;
  p[11] = 1;
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    if (n < 12 && p[n] == 1)
      cout << -1 << "\n";
    else if (n == 9)
      cout << 1 << "\n";
    else if (n < 12)
      cout << n / 4 << "\n";
    else if (n % 2 != 0)
      cout << 1 + (n - 9) / 4 << "\n";
    else
      cout << n / 4 << "\n";
  }
}
