#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  int n, q;
  cin >> q;
  while (q--) {
    cin >> n;
    if (n <= 3 || n == 5 || n == 7 || n == 11) {
      cout << "-1\n";
      continue;
      ;
    }
    int ans = n / 4;
    n = n % 4;
    if (n == 0)
      cout << ans;
    else if (n == 1)
      cout << ans - 1;
    else if (n == 2)
      cout << ans;
    else if (n == 3)
      cout << ans - 1;
    cout << "\n";
  }
}
