#include <bits/stdc++.h>
using namespace std;
int cal(int x) {
  if (x == 1 || x == 2 || x == 3 || x == 7 || x == 5 || x == 11) return -1;
  int tmp = x % 4, xx = x / 4;
  if (tmp == 0 || tmp == 2)
    return xx;
  else if (tmp == 1 || tmp == 3)
    return xx - 1;
}
int t, x;
int main() {
  cin >> t;
  while (t--) {
    cin >> x;
    cout << cal(x) << endl;
  }
}
