#include <bits/stdc++.h>
using namespace std;
void read(int &x) {
  x = 0;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c <= '9' && c >= '0') {
    x = x * 10 + c - 48;
    c = getchar();
  }
}
int f[20];
int main() {
  int q, x;
  f[4] = f[6] = f[9] = 1;
  f[8] = f[10] = 2;
  f[12] = 3;
  read(q);
  for (int i = 1; i <= q; i++) {
    read(x);
    if (x <= 12) {
      if (!f[x])
        cout << -1 << "\n";
      else
        cout << f[x] << "\n";
    } else {
      switch (x % 4) {
        case 0:
          cout << x / 4 << "\n";
          break;
        case 1:
          cout << x / 4 - 1 << "\n";
          break;
        case 2:
          cout << x / 4 << "\n";
          break;
        case 3:
          cout << x / 4 - 1 << "\n";
          break;
      }
    }
  }
}
