#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
using matrix = vector<vector<long long>>;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  while (q--) {
    int n;
    cin >> n;
    if (n == 1 || n == 2 || n == 3 || n == 5 || n == 7 || n == 11) {
      cout << -1 << '\n';
    } else if (n % 4 == 0) {
      cout << n / 4 << '\n';
    } else if (n % 4 == 1) {
      cout << 1 + (n - 9) / 4 << '\n';
    } else if (n % 4 == 2) {
      cout << 1 + (n - 6) / 4 << '\n';
    } else if (n % 4 == 3) {
      cout << 2 + (n - 15) / 4 << '\n';
    }
  }
}
