#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, ans = 0, flag = 0, t;
  cin >> t;
  while (t--) {
    flag = 0;
    cin >> n;
    m = n % 4;
    ans = n / 4;
    if (m == 1 && ans >= 2)
      ans--;
    else if (m == 2 && ans > 0)
      ;
    else if (m == 3 && ans >= 3)
      ans--;
    else if (m > 0)
      flag = 1;
    if (flag)
      cout << -1 << "\n";
    else
      cout << ans << "\n";
  }
}
