#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    if (n % 4 == 0)
      cout << (n / 4) << endl;
    else if (n == 2)
      cout << -1 << endl;
    else if (n < 12 && (n != 6 && n != 9 && n != 10))
      cout << -1 << endl;
    else {
      int p = n % 4;
      if (p == 1)
        cout << ((n - 9) / 4) + 1 << endl;
      else if (p == 2)
        cout << ((n - 6) / 4) + 1 << endl;
      else if (p == 3)
        cout << ((n - 11) / 4) + 1 << endl;
    }
  }
}
