#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int val = n / 4;
    if (n == 1 || n == 2 || n == 3 || n == 5 || n == 7 || n == 11) {
      cout << -1 << endl;
      continue;
    }
    if ((n % 4) == 0 || (n % 4) == 2) {
      cout << val << endl;
    } else if ((n % 4) == 1) {
      cout << (val - 1) << endl;
    } else if (n % 4 == 3) {
      int ans = (n - 15) / 4;
      ans = ans + 2;
      cout << ans << endl;
    }
  }
  return 0;
}
