#include <bits/stdc++.h>
#pragma optimize("O3")
using namespace std;
const long long MOD = 998244353;
const long long INF = 1e18 + 7;
const int base = 2e5 + 1;
const long long MAX = 1e6;
const double EPS = 1e-9;
const double PI = acos(-1.);
const int MAXN = 1e6 + 147;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {
  int q;
  cin >> q;
  while (q--) {
    int n;
    cin >> n;
    int x = n / 4;
    int y = (n - 4 * x) / 6;
    int z = (n - 4 * x - 6 * y) / 9;
    int mx = -1;
    for (int i = (max(0, x - 10)); i < (x + 10); ++i) {
      for (int j = (max(0, y - 10)); j < (y + 10); ++j) {
        for (int k = (max(0, z - 10)); k < (z + 10); ++k) {
          if (4 * i + 6 * j + 9 * k == n) {
            mx = max(mx, i + j + k);
          }
        }
      }
    }
    printf("%d\n", mx);
  }
  return 0;
}
