#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, c = 0;
    cin >> n;
    if (n % 2) {
      if (n < 13 && n != 9)
        cout << -1 << endl;
      else {
        c++;
        n -= 9;
        c += n / 4;
        cout << c << endl;
      }
    } else {
      if (n < 4)
        cout << -1 << endl;
      else {
        c += n / 4;
        cout << c << endl;
      }
    }
  }
}
