#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const unsigned gen_seed =
    std::chrono::system_clock::now().time_since_epoch().count();
std::mt19937_64 gen(gen_seed);
const int MAXN = 100000;
int main() {
  int t;
  scanf("%d", &t);
  for (int afaf = 0; afaf < t; afaf++) {
    int n;
    scanf("%d", &n);
    if (n < 4 || n == 5 || n == 7 || n == 11)
      printf("-1\n");
    else if (n % 4 == 0)
      printf("%d\n", n / 4);
    else if (n % 4 == 2)
      printf("%d\n", n / 4);
    else if (n % 4 == 1)
      printf("%d\n", n / 4 - 1);
    else if (n % 4 == 3)
      printf("%d\n", n / 4 - 1);
  }
}
