#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  long long ans = 0;
  if (n < 4) {
    cout << -1;
    return;
  }
  if (n % 4 == 1) {
    n -= 9;
    if (n < 0) {
      cout << -1;
      return;
    } else if (n == 0) {
      cout << 1;
      return;
    }
    ans += n / 4;
    cout << ans + 1;
    return;
  }
  if (n % 4 == 2) {
    n -= 6;
    if (n < 0) {
      cout << -1;
      return;
    } else if (n == 0) {
      cout << 1;
      return;
    }
    ans += n / 4;
    cout << ans + 1;
    return;
  }
  if (n % 4 == 3) {
    n -= 15;
    if (n < 0) {
      cout << -1;
      return;
    } else if (n == 0) {
      cout << 2;
      return;
    }
    ans += n / 4;
    cout << ans + 2;
    return;
  }
  ans += n / 4;
  cout << ans;
  return;
}
int main() {
  long long T;
  cin >> T;
  while (T--) {
    solve();
    cout << '\n';
  }
}
