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