#include <bits/stdc++.h>
using namespace std;
int n, m, tot;
int Fi[113], Si[113], Pi[113];
double pp[64][6400];
double ee[64][6400];
double ff[64][6400];
double calc(double E) {
  memset(pp, 0, sizeof(pp));
  for (int i = 0; i <= m; ++i)
    pp[n + 1][i] = 1., ff[n + 1][i] = 0., ee[n + 1][i] = 0.;
  for (int i = m + 1; i < m + 100; ++i)
    pp[n + 1][i] = 0., ff[n + 1][i] = 0., ee[n + 1][i] = 0.;
  for (int i = n; i >= 1; --i) {
    double succ = Pi[i] / 100., fail = 1. - succ;
    for (int j = 0; j < m + 100; ++j) {
      if (Si[i] + j < m + 100) {
        pp[i][j] = pp[i + 1][j + Fi[i]] * succ;
        ee[i][j] =
            succ * ee[i + 1][j + Fi[i]] + pp[i + 1][j + Fi[i]] * succ * Fi[i];
        ff[i][j] = succ * ff[i + 1][j + Fi[i]] +
                   (1. - pp[i + 1][j + Fi[i]]) * succ * Fi[i];
        pp[i][j] += pp[i + 1][j + Si[i]] * fail;
        ee[i][j] +=
            fail * ee[i + 1][j + Si[i]] + pp[i + 1][j + Si[i]] * fail * Si[i];
        ff[i][j] += fail * ff[i + 1][j + Si[i]] +
                    (1. - pp[i + 1][j + Si[i]]) * fail * Si[i];
        if (ee[i][j] + ff[i][j] > pp[i][j] * E) {
          pp[i][j] = 0.;
          ff[i][j] = 0.;
          ee[i][j] = 0.;
          if (i == 1 && j == 0) return 0x3f3f3f3f;
        }
      } else
        pp[i][j] = 0., ff[i][j] = 0., ee[i][j] = 0.;
    }
  }
  double Es = ee[1][0], Ef = ff[1][0], Ps = pp[1][0];
  return (Es + Ef) / Ps;
}
int main() {
  int T = 1;
  scanf("%d", &T);
  for (int ci = 1; ci <= T; ++ci) {
    scanf("%d", &n);
    int ans = n >> 2;
    if ((n & 3) == 1) {
      if (ans > 1)
        ans -= 1;
      else
        ans = -1;
    } else if ((n & 3) == 3) {
      if (ans > 2)
        ans -= 1;
      else
        ans = -1;
    }
    if (ans == 0) ans = -1;
    printf("%d\n", ans);
  }
  return 0;
}
