#include <bits/stdc++.h>
using namespace std;
const int inf_int = 1e9 + 100;
const long long inf_ll = 1e18;
const double pi = 3.1415926535898;
bool debug = 0;
const int MAXN = 3e5 + 100;
const int LOG = 21;
const int mod = 1e9 + 7;
const int MX = (1e6 + 100);
template <class T1, class T2>
std::ostream &operator<<(std::ostream &out, const std::pair<T1, T2> &rhs) {
  out << "( " << rhs.first << " , " << rhs.second << " )";
  return out;
}
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string &s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
int dp[1000];
bool is_prime(int x) {
  for (int i = 2; 1ll * i * i <= x; ++i) {
    if (x % i == 0) {
      return false;
    }
  }
  return true;
}
void solve() {
  vector<int> comp;
  for (int i = 1; i <= 100; ++i) {
    if (is_prime(i)) {
    } else {
      comp.push_back(i);
    }
  }
  dp[0] = 0;
  dp[1] = dp[2] = dp[3] = -inf_int;
  for (int i = 1; i <= 100; ++i) {
    dp[i] = -inf_int;
    for (int v : comp) {
      if (v <= i) {
        dp[i] = max(dp[i], dp[i - v] + 1);
      }
    }
  }
  int q;
  cin >> q;
  for (int i = 1; i <= q; ++i) {
    int x;
    cin >> x;
    int ans = -1;
    for (int val = 0; val <= 100 && val <= x; ++val) {
      if ((x - val) % 4 == 0) {
        ans = max(ans, dp[val] + (x - val) / 4);
      }
    }
    cout << ans << "\n";
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout.setf(ios::fixed);
  cout.precision(15);
  int t = 1;
  while (t--) solve();
  42;
}
