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