#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const int SZ = 200010, INF = 0x7FFFFFFF;
const double EPS = 1e-8;
int main() {
  std::ios::sync_with_stdio(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    if (x == 1 || x == 2 || x == 3 || x == 5 || x == 7 || x == 11)
      cout << -1 << endl;
    else if (x % 4 == 0)
      cout << x / 4 << endl;
    else if (x % 4 == 1)
      cout << x / 4 - 1 << endl;
    else if (x % 4 == 2)
      cout << x / 4 << endl;
    else {
      cout << x / 4 - 1 << endl;
    }
  }
  return 0;
}
