#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int q;
  cin >> q;
  while (q--) {
    long long int n, k = 0;
    cin >> n;
    if (n % 2 != 0) {
      n = n - 9;
      k++;
    }
    if (n == 2 || n < 0) {
      cout << -1 << "\n";
      continue;
    } else if (n == 0) {
      cout << k << "\n";
      continue;
    }
    if (n % 4 == 0) {
      cout << n / 4 + k << "\n";
    } else {
      k++;
      n = n - 6;
      cout << n / 4 + k << "\n";
    }
  }
}
