#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int q;
  cin >> q;
  while (q--) {
    long long int n;
    cin >> n;
    if (n == 1 || n == 2 || n == 3 || n == 5 || n == 7 || n == 11) {
      cout << -1;
    } else if (n == 9) {
      cout << 1;
    } else if (n & 1) {
      n -= 9;
      cout << (n / 4) + 1;
    } else {
      cout << n / 4;
    }
    cout << '\n';
  }
  return 0;
}
