#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  int q;
  cin >> q;
  while (q--) {
    int n;
    cin >> n;
    if (n < 4) {
      cout << -1 << '\n';
      continue;
    }
    if (n == 9) {
      cout << 1 << '\n';
      continue;
    }
    int ans = 0;
    if (n % 2 == 1) {
      if (n - 9 < 4) {
        cout << -1 << '\n';
        continue;
      }
      n -= 9;
      ans++;
    }
    if (n % 4 == 0) {
      ans += n / 4;
      cout << ans << '\n';
    } else {
      ans++;
      n -= 6;
      ans += n / 4;
      cout << ans << '\n';
    }
  }
  return 0;
}
