#include <bits/stdc++.h>
using namespace std;
void Weapons19() {
  cin.sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
int32_t main() {
  Weapons19();
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    long long a;
    cin >> a;
    long long x = a / 4;
    long long y = a % 4;
    if (y == 0)
      cout << x << "\n";
    else if (y == 1) {
      if (x > 1)
        cout << x - 1 << "\n";
      else
        cout << -1 << "\n";
    } else if (y == 2) {
      if (x >= 1)
        cout << x << "\n";
      else
        cout << -1 << "\n";
    } else if (y == 3) {
      if (x > 2)
        cout << x - 1 << "\n";
      else
        cout << -1 << "\n";
    }
  }
}
