#include <bits/stdc++.h>
using namespace std;
long long q, t;
bool f(long long x) {
  for (long long i = 2; i * i <= x; i++)
    if (x % i == 0) return false;
  return true;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> q;
  while (q--) {
    long long ans = 0;
    cin >> t;
    {
      if (t == 2) {
        cout << -1 << endl;
        continue;
      }
      if (t == 9) {
        cout << 1 << endl;
        continue;
      }
      if (t % 2 == 1) {
        t -= 9;
        if (t < 4) {
          cout << -1 << endl;
          continue;
        } else
          ans++;
      }
      if (t % 4 == 0)
        cout << t / 4 + ans << endl;
      else if (t % 4 == 2)
        cout << t / 4 + ans << endl;
      else if (t % 6 == 0)
        cout << t / 6 + ans << endl;
      else if (t % 6 == 4)
        cout << t / 6 + 1 + ans << endl;
      else
        cout << 1 << endl;
    }
  }
  return 0;
}
