#include <bits/stdc++.h>
using namespace std;
int getNum(int data) {
  switch (data % 4) {
    case 0:
      return data / 4;
    case 1:
      if (data >= 9) return data / 4 - 1;
      break;
    case 2:
      if (data >= 6) return data / 4;
      break;
    case 3:
      if (data >= 15) return data / 4 - 1;
      break;
  }
  return -1;
}
int main() {
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int temp;
    cin >> temp;
    int result = getNum(temp);
    if (result > 0)
      cout << result;
    else
      cout << -1;
    cout << endl;
  }
  return 0;
}
