#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7;
const int mod = 1e9 + 7;
const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
int num[] = {1, 2, 3, 5, 7, 11};
int f(int x) {
  for (int i = 0; i < 6; ++i) {
    if (x == num[i]) return -1;
  }
  return x / 4 - x % 2;
}
int main() {
  int n;
  cin >> n;
  int a;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a);
    printf("%d\n", f(a));
  }
  return 0;
}
