#include <bits/stdc++.h>
using namespace std;
int main() {
  int min = INT_MIN, t, n, c;
  int a[] = {min, min, min, 1, min, 1, min, 2, 1, 2,
             min, 3,   2,   3, 2,   4, 3,   4, 3, 5};
  cin >> t;
  while (t--) {
    cin >> n;
    if (n <= 20) {
      c = a[n - 1];
      if (c < 0) {
        cout << -1 << endl;
      } else {
        cout << c << endl;
      }
    } else {
      c = 0;
      while (n > 20) {
        n -= 4;
        c++;
      }
      if (a[n - 1] < 0) {
        cout << -1 << endl;
      } else {
        c = c + a[n - 1];
        cout << c << endl;
      }
    }
  }
  return 0;
}
