#include <bits/stdc++.h>
using namespace std;
long long int a[2000000];
using cd = complex<long double>;
vector<cd> A(262144 * 2), B(262144 * 2);
vector<cd> C(262144 * 2);
const double PI = acos(-1);
void fft(vector<cd> &a, bool invert) {
  int n = a.size();
  for (int i = 1, j = 0; i < n; i++) {
    int bit = n >> 1;
    for (; j & bit; bit >>= 1) j ^= bit;
    j ^= bit;
    if (i < j) swap(a[i], a[j]);
  }
  for (int len = 2; len <= n; len <<= 1) {
    double ang = 2 * PI / len * (invert ? -1 : 1);
    cd wlen(cos(ang), sin(ang));
    for (int i = 0; i < n; i += len) {
      cd w(1);
      for (int j = 0; j < len / 2; j++) {
        cd u = a[i + j], v = a[i + j + len / 2] * w;
        a[i + j] = u + v;
        a[i + j + len / 2] = u - v;
        w *= wlen;
      }
    }
  }
  if (invert) {
    for (cd &x : a) x /= n;
  }
}
void prod(vector<cd> &a, vector<cd> &b, vector<cd> &c) {
  for (int i = 0; i < a.size(); i++) {
    c[i] = a[i] * b[i];
  }
}
int ans[2000000];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, x, y;
  cin >> n >> x >> y;
  for (int i = 0; i < 262144 * 2; i++) A[i] = 0;
  for (int i = 0; i < 262144 * 2; i++) B[i] = 0;
  for (int i = 0; i < n + 1; i++) {
    cin >> a[i];
    A[a[i]] += cd(1, 0);
    B[x - a[i]] += cd(1, 0);
  }
  fft(A, 0);
  fft(B, 0);
  prod(A, B, C);
  fft(C, 1);
  set<int> diff;
  for (int i = x + 1; i < 262144 * 2; i++) {
    if (round(C[i].real()) > 0) {
      diff.insert(i - x);
    }
  }
  for (int i = 0; i < 2000000; i++) ans[i] = -1;
  for (auto a : diff) {
    for (int i = 2 * y + 2 * a; i < 2000000; i += 2 * a + 2 * y) {
      ans[i] = max(ans[i], 2 * y + 2 * a);
    }
  }
  int q;
  cin >> q;
  while (q--) {
    int x;
    cin >> x;
    cout << ans[x] << " ";
  }
  cout << endl;
  return 0;
}
