#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const int mod = 1e9 + 7;
const int N = 1e5 + 10;
inline int add(int x, int y) {
  x += y;
  if (x >= mod) x -= mod;
  return x;
}
inline int mul(int x, int y) {
  x = (1LL * x * y) % mod;
  return x;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int ans = -1;
    if (n % 4 == 0) {
      ans = n / 4;
    } else if (n % 4 == 1) {
      ans = (n - 9) / 4 + 1;
    } else if (n % 4 == 2) {
      ans = (n - 6) / 4 + 1;
    } else if (n % 4 == 3 and n != 11) {
      ans = (n - 15) / 4 + 2;
    }
    if (ans < 1) ans = -1;
    cout << ans << "\n";
  }
  return 0;
}
