#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    long long int a[] = {4, 6, 9};
    vector<long long int> dp(16, -1);
    dp[0] = 0;
    for (int i = 1; i <= 16; i++) {
      for (int j = 0; j < 3; j++) {
        if (i >= a[j] && dp[i - a[j]] != -1) {
          dp[i] = max(dp[i], dp[i - a[j]] + 1);
        }
      }
    }
    if (n <= 15) {
      cout << dp[n] << endl;
    } else {
      long long int t = (n - 16) / 4 + 1;
      long long int ans = t + dp[n - 4 * t];
      cout << ans << endl;
    }
  }
}
