#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
template <typename T>
T pow(T a, T b, long long m) {
  T ans = 1;
  while (b > 0) {
    if (b % 2 == 1) ans = (ans * a) % m;
    b /= 2;
    a = (a * a) % m;
  }
  return ans % m;
}
const long long N = 1e6 + 5;
const long long MOD = 1e9 + 7;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long q;
  cin >> q;
  while (q--) {
    long long n;
    cin >> n;
    if (n == 1 || n == 2 || n == 3 || n == 5 || n == 7 || n == 11) {
      cout << "-1"
           << "\n";
      continue;
    }
    long long ans = n / 4;
    long long rem = n % 4;
    if (rem % 2) ans--;
    cout << ans << "\n";
  }
  return 0;
}
