#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  ;
  if (n < 8) {
    if (n == 4 || n == 6)
      cout << "1";
    else
      cout << "-1";
    cout << "\n";
    return;
  }
  if (n == 11) {
    cout << "-1"
         << "\n";
    return;
  }
  long long a = n % 4;
  if (a == 0)
    cout << n / 4;
  else if (a == 1)
    cout << n / 4 - 1;
  else if (a == 2)
    cout << n / 4;
  else
    cout << n / 4 - 1;
  cout << "\n";
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
