#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q;
  cin >> q;
  int d[6] = {1, 2, 3, 5, 7, 11};
  for (int i = 0; i < q; i++) {
    cin >> n;
    if (n == 1 || n == 2 || n == 3 || n == 5 || n == 7 || n == 11) {
      cout << "-1" << endl;
      continue;
    }
    int m = 0;
    if (n % 2 == 1) {
      n -= 9;
      m = 1;
    }
    if (n % 4 == 0) {
      cout << m + (n / 4) << endl;
      continue;
    }
    if (n % 4 == 2) {
      cout << (n - 6) / 4 + 1 + m << endl;
      continue;
    }
  }
}
