#include <bits/stdc++.h>
using namespace std;
int ans(int x) {
  long long int ar[16];
  ar[1] = -1;
  ar[2] = -1;
  ar[3] = -1;
  ar[5] = -1;
  ar[7] = -1;
  ar[11] = -1;
  ar[4] = 1;
  ar[6] = 1;
  ar[9] = 1;
  ar[8] = 2;
  ar[10] = 2;
  ar[13] = 2;
  ar[15] = 2;
  ar[12] = 3;
  ar[14] = 3;
  return ar[x];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    if (n <= 15) {
      cout << ans(n) << endl;
    } else {
      long long int t = (n - 16) / 4 + 1;
      cout << t + ans(n - 4 * t) << endl;
    }
  }
}
