#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    if (n < 4 || n == 5 || n == 7 || n == 11)
      cout << -1 << endl;
    else if (n == 4 || n == 6 || n == 9)
      cout << 1 << endl;
    else if (n % 2 == 0)
      cout << n / 4 << endl;
    else if (n % 2)
      cout << n / 4 - 1 << endl;
  }
}
