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