#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int maxn = (1<<21)+5;
const int maxN = 1000005;
const double pi = acos(-1.0);

struct comp {
    double r,i;
    comp (double r=0,double i=0):r(r),i(i){}
    comp operator +(comp x) {return comp(r+x.r,i+x.i);}
    comp operator -(comp x) {return comp(r-x.r,i-x.i);}
    comp operator *(comp x) {return comp(r*x.r-i*x.i,i*x.r+r*x.i);}
};

void rader(comp *a,int len) {
    int j=len>>1;
    for(int i=1;i<len-1;i++) {
        if(i<j) swap(a[i],a[j]);
        int k=len>>1;
        while(k&j) {
            j^=k;k>>=1;
        }
        j^=k;
    }
}

void FFT(comp *a,int t,int len) {
    rader(a,len);
    for(int h=1;h<len;h<<=1) {
        comp wn = comp(cos(-t*pi/h),sin(-t*pi/h));
        int step=h*2;
        for(int i=0;i<len;i+=step) {
            comp e(1,0);
            for(int j=i;j<i+h;j++) {
                comp u=a[j],v=e*a[j+h];
                a[j]=u+v;a[j+h]=u-v;
                e=e*wn;
            }
        }
    }
    if(t==-1) {
        for(int i=0;i<len;i++) a[i].r/=1.0*len;
    }
}

comp f[maxn],g[maxn];
int ans[maxN];

int main() {
    int n,x,y;scanf("%d%d%d",&n,&x,&y);
    for(int i=0;i<=n;i++) {
        int p;scanf("%d",&p);
        f[p].r++;g[x-p].r++;
    }

    int len=1;while(len<x+x) len<<=1;
    FFT(f,1,len);FFT(g,1,len);
    for(int i=0;i<len;i++) f[i]=f[i]*g[i];
    FFT(f,-1,len);

    for(int i=1;i<=x;i++) {
        int p1 = (int)(f[i+x].r+0.5),p2 = (int)(f[x-i].r+0.5);
        if(p1) {
            //printf("i = %d\n",i);
            for(int j=2*(i+y);j<maxN;j+=2*(i+y)) {
                ans[j]=2*(i+y);
            }
        }
    }
    int q;scanf("%d",&q);
    while(q--) {
        int li;scanf("%d",&li);
        if(ans[li]) printf("%d ",ans[li]);
        else printf("%d ",-1);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

/** Interface */

inline int readChar();
template <class T = int> inline T readInt();
template <class T> inline void writeInt( T x, char end = 0 );
inline void writeChar( int x );
inline void writeWord( const char *s );

/** Read */

static const int buf_size = 4096;

inline int getChar() {
	static char buf[buf_size];
	static int len = 0, pos = 0;
	if (pos == len)
		pos = 0, len = fread(buf, 1, buf_size, stdin);
	if (pos == len)
		return -1;
	return buf[pos++];
}

inline int readChar() {
	int c = getChar();
	while (c <= 32)
		c = getChar();
	return c;
}

template <class T>
inline T readInt() {
	int s = 1, c = readChar();
	T x = 0;
	if (c == '-')
		s = -1, c = getChar();
	while ('0' <= c && c <= '9')
		x = x * 10 + c - '0', c = getChar();
	return s == 1 ? x : -x;
}

/** Write */

static int write_pos = 0;
static char write_buf[buf_size];

inline void writeChar( int x ) {
	if (write_pos == buf_size)
		fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;
	write_buf[write_pos++] = x;
}

template <class T>
inline void writeInt( T x, char end ) {
	if (x < 0)
		writeChar('-'), x = -x;

	char s[24];
	int n = 0;
	while (x || !n)
		s[n++] = '0' + x % 10, x /= 10;
	while (n--)
		writeChar(s[n]);
	if (end)
		writeChar(end);
}

inline void writeWord( const char *s ) {
	while (*s)
		writeChar(*s++);
}

struct Flusher {
	~Flusher() {
		if (write_pos)
			fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;
	}
} flusher;

const int MAXN = 200001;
//const int MAXN = 11;
const int MAXX = 1e6+7;
typedef bitset<MAXN> DP;

int a[MAXN];
int ans[MAXX];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n = readInt();
    int x = readInt();
    int y = readInt();
//    cin >> n >> x >> y;
    for (int i = 0; i <= n; i++) a[i] = readInt();

    DP total;
    DP pre;
    for (int i = 0; i < n; i++) {
        pre.set(0, 1);
        total |= (pre <<= a[i+1]-a[i]);
//        cout << pre << endl;
//        cout << total << endl;
    }

    memset(ans, -1, sizeof ans);
    for (int i = x; i > 0; i--) {
        if (total.test(i) == 0) continue;
//        cout << "=> " << i << endl;
        int p = (y+i)*2;
        for (int j = p; j < MAXX; j += p) {
            if (ans[j]!=-1) continue;
            ans[j] = p;
        }
    }

    int q = readInt();
//    cin >> q;

    while (q--) {
        int x = readInt();
//        cin >> x;
//        cout << ans[x] << " ";
        writeInt(ans[x]);
        writeChar(' ');
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/** Interface */

inline int readChar();
template <class T = int> inline T readInt();
template <class T> inline void writeInt( T x, char end = 0 );
inline void writeChar( int x );
inline void writeWord( const char *s );

/** Read */

static const int buf_size = 4096;

inline int getChar() {
	static char buf[buf_size];
	static int len = 0, pos = 0;
	if (pos == len)
		pos = 0, len = fread(buf, 1, buf_size, stdin);
	if (pos == len)
		return -1;
	return buf[pos++];
}

inline int readChar() {
	int c = getChar();
	while (c <= 32)
		c = getChar();
	return c;
}

template <class T>
inline T readInt() {
	int s = 1, c = readChar();
	T x = 0;
	if (c == '-')
		s = -1, c = getChar();
	while ('0' <= c && c <= '9')
		x = x * 10 + c - '0', c = getChar();
	return s == 1 ? x : -x;
}

/** Write */

static int write_pos = 0;
static char write_buf[buf_size];

inline void writeChar( int x ) {
	if (write_pos == buf_size)
		fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;
	write_buf[write_pos++] = x;
}

template <class T>
inline void writeInt( T x, char end ) {
	if (x < 0)
		writeChar('-'), x = -x;

	char s[24];
	int n = 0;
	while (x || !n)
		s[n++] = '0' + x % 10, x /= 10;
	while (n--)
		writeChar(s[n]);
	if (end)
		writeChar(end);
}

inline void writeWord( const char *s ) {
	while (*s)
		writeChar(*s++);
}

struct Flusher {
	~Flusher() {
		if (write_pos)
			fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;
	}
} flusher;

const int MAXN = 200001;
//const int MAXN = 11;
const int MAXX = 1e6+7;
typedef bitset<MAXN> DP;

int a[MAXN];
int ans[MAXX];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n = readInt();
    int x = readInt();
    int y = readInt();
//    cin >> n >> x >> y;
    for (int i = 0; i <= n; i++) a[i] = readInt();

    DP total;
    DP pre;
    for (int i = 0; i < n; i++) {
        pre.set(0, 1);
        total |= (pre <<= a[i+1]-a[i]);
//        cout << pre << endl;
//        cout << total << endl;
    }

    memset(ans, -1, sizeof ans);
    for (int i = x; i > 0; i--) {
        if (total.test(i) == 0) continue;
//        cout << "=> " << i << endl;
        int p = (y+i)*2;
        for (int j = p; j < MAXX; j += p) {
            if (ans[j]!=-1) continue;
            ans[j] = p;
        }
    }

    int q = readInt();
//    cin >> q;

    while (q--) {
        int x = readInt();
//        cin >> x;
//        cout << ans[x] << " ";
        writeInt(ans[x]);
        writeChar(' ');
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

/** Interface */

inline int readChar();
template <class T = int> inline T readInt();
template <class T> inline void writeInt( T x, char end = 0 );
inline void writeChar( int x );
inline void writeWord( const char *s );

/** Read */

static const int buf_size = 4096;

inline int getChar() {
	static char buf[buf_size];
	static int len = 0, pos = 0;
	if (pos == len)
		pos = 0, len = fread(buf, 1, buf_size, stdin);
	if (pos == len)
		return -1;
	return buf[pos++];
}

inline int readChar() {
	int c = getChar();
	while (c <= 32)
		c = getChar();
	return c;
}

template <class T>
inline T readInt() {
	int s = 1, c = readChar();
	T x = 0;
	if (c == '-')
		s = -1, c = getChar();
	while ('0' <= c && c <= '9')
		x = x * 10 + c - '0', c = getChar();
	return s == 1 ? x : -x;
}

/** Write */

static int write_pos = 0;
static char write_buf[buf_size];

inline void writeChar( int x ) {
	if (write_pos == buf_size)
		fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;
	write_buf[write_pos++] = x;
}

template <class T>
inline void writeInt( T x, char end ) {
	if (x < 0)
		writeChar('-'), x = -x;

	char s[24];
	int n = 0;
	while (x || !n)
		s[n++] = '0' + x % 10, x /= 10;
	while (n--)
		writeChar(s[n]);
	if (end)
		writeChar(end);
}

inline void writeWord( const char *s ) {
	while (*s)
		writeChar(*s++);
}

struct Flusher {
	~Flusher() {
		if (write_pos)
			fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;
	}
} flusher;

const int MAXN = 200001;
//const int MAXN = 11;
const int MAXX = 1e6+7;
typedef bitset<MAXN> DP;

int a[MAXN];
int ans[MAXX];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n = readInt();
    int x = readInt();
    int y = readInt();
//    cin >> n >> x >> y;
    for (int i = 0; i <= n; i++) a[i] = readInt();

    DP total;
    DP pre;
    for (int i = 0; i < n; i++) {
        pre.set(0, 1);
        pre <<= a[i+1]-a[i];
        total |= pre;
//        cout << pre << endl;
//        cout << total << endl;
    }

    memset(ans, -1, sizeof ans);
    for (int i = x; i > 0; i--) {
        if (total.test(i) == 0) continue;
//        cout << "=> " << i << endl;
        int p = (y+i)*2;
        for (int j = p; j < MAXX; j += p) {
            if (ans[j]!=-1) continue;
            ans[j] = p;
        }
    }

    int q = readInt();
//    cin >> q;

    while (q--) {
        int x = readInt();
//        cin >> x;
//        cout << ans[x] << " ";
        writeInt(x);
        writeChar(' ');
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN = 200001;
//const int MAXN = 11;
const int MAXX = 1e6+7;
typedef bitset<MAXN> DP;

int a[MAXN];
int ans[MAXX];

vector< int >divisor[MAXX];

void init() {
    for (int i = 1; i < MAXX; i++) {
        for (int j = i; j < MAXX; j += i) {
            divisor[j].push_back(i);
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    init();

    int n, x, y;
    cin >> n >> x >> y;
    for (int i = 0; i <= n; i++) cin >> a[i];

    DP total;
    DP pre;
    for (int i = 0; i < n; i++) {
        pre.set(0, 1);
        pre <<= a[i+1]-a[i];
        total |= pre;
    }

//    for (int i = x; i > 0; i--) {
//        if (total.test(i) == 0) continue;
////        cout << "=> " << i << endl;
//        int p = (y+i)*2;
//        for (int j = p; j < MAXX; j += p) {
//            if (ans[j]!=-1) continue;
//            ans[j] = p;
//        }
//    }

    int q;
    cin >> q;

    while (q--) {
        int l;
        cin >> l;

        if (ans[l]==0) {
            ans[l] = -1;
            reverse(divisor[l].begin(), divisor[l].end());
            for (int d : divisor[l]) {
                int g = (d/2)-y;
                if (g <= 0) break;
                if (g <= x && total[g]) {
                    ans[l] = d;
                    break;
                }
            }
        }

        cout << ans[l] << " ";
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN = 200001;
//const int MAXN = 11;
const int MAXX = 1e6+7;
typedef bitset<MAXN> DP;

int a[MAXN];
int ans[MAXX];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, x, y;
    cin >> n >> x >> y;
    for (int i = 0; i <= n; i++) cin >> a[i];

    DP total;
    DP pre;
    for (int i = 0; i < n; i++) {
        pre.set(0, 1);
        pre <<= a[i+1]-a[i];
        total |= pre;
//        cout << pre << endl;
//        cout << total << endl;
    }

    memset(ans, -1, sizeof ans);
    for (int i = x; i > 0; i--) {
        if (total.test(i) == 0) continue;
//        cout << "=> " << i << endl;
        int p = (y+i)*2;
        for (int j = p; j < MAXX; j += p) {
            if (ans[j]!=-1) continue;
            ans[j] = p;
        }
    }

    int q;
    cin >> q;

    while (q--) {
        int x;
        cin >> x;
        cout << ans[x] << " ";
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

/** Interface */

inline int readChar();
template <class T = int> inline T readInt();
template <class T> inline void writeInt( T x, char end = 0 );
inline void writeChar( int x );
inline void writeWord( const char *s );

/** Read */

static const int buf_size = 4096;

inline int getChar() {
	static char buf[buf_size];
	static int len = 0, pos = 0;
	if (pos == len)
		pos = 0, len = fread(buf, 1, buf_size, stdin);
	if (pos == len)
		return -1;
	return buf[pos++];
}

inline int readChar() {
	int c = getChar();
	while (c <= 32)
		c = getChar();
	return c;
}

template <class T>
inline T readInt() {
	int s = 1, c = readChar();
	T x = 0;
	if (c == '-')
		s = -1, c = getChar();
	while ('0' <= c && c <= '9')
		x = x * 10 + c - '0', c = getChar();
	return s == 1 ? x : -x;
}

/** Write */

static int write_pos = 0;
static char write_buf[buf_size];

inline void writeChar( int x ) {
	if (write_pos == buf_size)
		fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;
	write_buf[write_pos++] = x;
}

template <class T>
inline void writeInt( T x, char end ) {
	if (x < 0)
		writeChar('-'), x = -x;

	char s[24];
	int n = 0;
	while (x || !n)
		s[n++] = '0' + x % 10, x /= 10;
	while (n--)
		writeChar(s[n]);
	if (end)
		writeChar(end);
}

inline void writeWord( const char *s ) {
	while (*s)
		writeChar(*s++);
}

struct Flusher {
	~Flusher() {
		if (write_pos)
			fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;
	}
} flusher;

const int MAXN = 200001;
//const int MAXN = 11;
const int MAXX = 1e6+7;
typedef bitset<MAXN> DP;

int a[MAXN];
int ans[MAXX];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n = readInt();
    int x = readInt();
    int y = readInt();
//    cin >> n >> x >> y;
    for (int i = 0; i <= n; i++) a[i] = readInt();

    DP total;
    DP pre;
    for (int i = 0; i < n; i++) {
        pre.set(0, 1);
        pre <<= a[i+1]-a[i];
        total |= pre;
//        cout << pre << endl;
//        cout << total << endl;
    }

    memset(ans, -1, sizeof ans);
    for (int i = x; i > 0; i--) {
        if (total.test(i) == 0) continue;
//        cout << "=> " << i << endl;
        int p = (y+i)*2;
        for (int j = p; j < MAXX; j += p) {
            if (ans[j]!=-1) continue;
            ans[j] = p;
        }
    }

    int q = readInt();
//    cin >> q;

    while (q--) {
        int x = readInt();
//        cin >> x;
//        cout << ans[x] << " ";
        writeInt(ans[x]);
        writeChar(' ');
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN = 200001;
//const int MAXN = 11;
const int MAXX = 1e6+7;
typedef bitset<MAXN> DP;

int a[MAXN];
int ans[MAXX];

vector< int >divisor[MAXX];

void init() {
    for (int i = 2; i < MAXX; i+=2) {
        for (int j = i; j < MAXX; j += i) {
            divisor[j].push_back(i);
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    init();

    int n, x, y;
    cin >> n >> x >> y;
    for (int i = 0; i <= n; i++) cin >> a[i];

    DP total;
    DP pre;
    for (int i = 0; i < n; i++) {
        pre.set(0, 1);
        pre <<= a[i+1]-a[i];
        total |= pre;
    }

//    for (int i = x; i > 0; i--) {
//        if (total.test(i) == 0) continue;
////        cout << "=> " << i << endl;
//        int p = (y+i)*2;
//        for (int j = p; j < MAXX; j += p) {
//            if (ans[j]!=-1) continue;
//            ans[j] = p;
//        }
//    }

    int q;
    cin >> q;

    while (q--) {
        int l;
        cin >> l;

        if (ans[l]==0) {
            ans[l] = -1;
            reverse(divisor[l].begin(), divisor[l].end());
            for (int d : divisor[l]) {
                int g = (d/2)-y;
                if (g <= 0) break;
                if (g <= x && total[g]) {
                    ans[l] = d;
                    break;
                }
            }
        }

        cout << ans[l] << " ";
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
const int MAXN = 200001;
//const int MAXN = 11;
const int MAXX = 1e6+7;
typedef bitset<MAXN> DP;

int a[MAXN];
int ans[MAXX];

vector< int >divisor[MAXX];

void init() {
    for (int i = 2; i < MAXX; i+=2) {
        for (int j = i; j < MAXX; j += i) {
            divisor[j].push_back(i);
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    init();

    int n, x, y;
    cin >> n >> x >> y;
    for (int i = 0; i <= n; i++) cin >> a[i];

    DP total;
    DP pre;
    for (int i = 0; i < n; i++) {
        pre.set(0, 1);
        pre <<= a[i+1]-a[i];
        total |= pre;
    }

//    for (int i = x; i > 0; i--) {
//        if (total.test(i) == 0) continue;
////        cout << "=> " << i << endl;
//        int p = (y+i)*2;
//        for (int j = p; j < MAXX; j += p) {
//            if (ans[j]!=-1) continue;
//            ans[j] = p;
//        }
//    }

    int q;
    cin >> q;

    while (q--) {
        int l;
        cin >> l;

        if (ans[l]==0) {
            ans[l] = -1;
            reverse(divisor[l].begin(), divisor[l].end());
            for (int d : divisor[l]) {
                int g = (d/2)-y;
                if (g <= 0) break;
                if (g <= x && total[g]) {
                    ans[l] = d;
                    break;
                }
            }
        }

        cout << ans[l] << " ";
    }

    return 0;
}


//Forever... Check size - Reading order - Use scanf - Clear structures
#pragma GCC optimize ("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define sz(x) int(x.size())
#define pb push_back
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ff first
#define ss second
#define REP(i,a,b) for(int i = int(a); i < int(b); ++ i)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

const double PI = acos(-1);
const int N = (1 << 21);

struct Cpx{
	double r, i;
	Cpx(double r = 0, double i = 0): r(r), i(i){}
	double real() const{ return r; }
	void operator /= (const int c){ r /= c, i /= c;}
};

Cpx operator * (const Cpx &a, const Cpx &b){return Cpx(a.r*b.r - a.i*b.i, a.r*b.i + a.i*b.r);}
Cpx operator + (const Cpx &a, const Cpx &b){return Cpx(a.r + b.r, a.i + b.i);}
Cpx operator - (const Cpx &a, const Cpx &b){return Cpx(a.r - b.r, a.i - b.i);}

Cpx cp1[N+9], cp2[N+9];
int R[N+9];

void fft(Cpx *a, int n, bool inv){
	REP(i,0,n) if(R[i] < i) swap(a[R[i]], a[i]);
	for(int m = 2; m <= n; m *= 2){
		double z = 2 * PI / m * (inv ? -1 : 1);
		Cpx wi = Cpx(cos(z), sin(z));
		for(int j = 0; j < n; j += m){
			Cpx w(1);
			for(int k = j, k2 = j + m/2; k2 < j + m; k ++, k2 ++){
				Cpx u = a[k]; Cpx v = a[k2] * w;
				a[k] = u + v, a[k2] = u - v;
				w = w * wi;
			}
		}
	}
	if(inv) REP(i,0,n) a[i] /= n;
}

typedef vector<ld> Poly;

Poly add(Poly &p1, Poly &p2){
	int high = max(sz(p1), sz(p2));
	Poly res(high, 0);
	REP(i,0,high) {
		if(i < sz(p1)) res[i] += p1[i];
		if(i < sz(p2)) res[i] += p2[i];
	}
	return res;
}

Poly mul(Poly &p1, Poly &p2){
	int n = sz(p1) + sz(p2) + 1;
	int m = 1, cnt = 0;
	while(m <= n) m += m, cnt ++;
	REP(i,0,m){ R[i] = 0; REP(j,0,cnt) R[i] = (R[i] << 1) | ((i >> j) & 1); }
	REP(i,0,m) cp1[i] = 0, cp2[i] = 0;
	REP(i,0,sz(p1)) cp1[i] = p1[i];
	REP(i,0,sz(p2)) cp2[i] = p2[i];
	fft(cp1, m, false); fft(cp2, m, false);
	REP(i,0,m) cp1[i] = cp1[i] * cp2[i];
	fft(cp1, m, true);
	Poly res;
	n -= 2;
	REP(i,0,n){ res.pb((ll)floor(cp1[i].real() + 0.5));}
	return res;
}

const int off = 2e5;

int main(){
	fastio;
	int n, x, y; cin >> n >> x >> y;
	Poly f(2*off + 1, 0), g(2*off+1,0);
	REP(i,0,n+1){
		int a; cin >> a;
		f[off + a] ++;
		g[off - a] ++;
	}
	f = mul(f, g);

	int q; cin >> q;
	set<int, greater<int> > s;
	while(q --){
		s.clear();
		int num; cin >> num;
		for(int d = 1; d * d <= num; ++ d){
			if(num % d == 0){
				int p = d, q = num / d;
				s.insert(p);
				if(p != q) s.insert(q);
			}
		}
		int ans = -1;
		for(auto u: s){
			u -= 2 * y;
			if(u <= 0 or u % 2) continue;
			u /= 2;
			if(f[2*off + u]) {ans = 2 * (u + y); break;}
		}
		cout << ans << " ";
	}
	cout << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const ll P = 998244353, R = 3;

int N = 524288;

ll pw(ll x, ll y) {
    ll ret = 1;
    while(y) {
        if(y & 1) ret = ret * x % P;
        x = x * x % P;
        y >>= 1;
    }
    return ret;
}

void fft(int N, vector<ll>& a, bool f) {
    ll i, j, k, x, y, z;
    j = 0;
    for(i = 1; i < N; i++) {
        for(k = N >> 1; j >= k; k >>= 1) j -= k;
        j += k;
        if(i < j) {
            k = a[i];
            a[i] = a[j];
            a[j] = k;
        }
    }
    for(i = 1; i < N; i <<= 1) {
        x = pw(f ? pw(R, P - 2) : R, P / i >> 1);
        for(j = 0; j < N; j += i << 1) {
            y = 1;
            for(k = 0; k < i; k++) {
                z = a[i | j | k] * y % P;
                a[i | j | k] = a[j | k] - z;
                if(a[i | j | k] < 0) a[i | j | k] += P;
                a[j | k] += z;
                if(a[j | k] >= P) a[j | k] -= P;
                y = y * x % P;
            }
        }
    }
    if(f) {
        j = pw(N, P - 2);
        for(i = 0; i < N; i++) a[i] = a[i] * j % P;
    }
}

void multiply(int N, vector<ll>& X, vector<ll>& Y) {
    fft(N, X, false);
    fft(N, Y, false);
    for(int i = 0; i < N; i++) X[i] = X[i] * Y[i] % P;
    fft(N, X, true);
}

vector<ll> A(N), B(N);
int M, XX, YY;
int ans[505050];
int Q;

int main() {
    scanf("%d%d%d", &M, &XX, &YY);
    M++;
    for(int i = 1; i <= M; i++) {
        int a; scanf("%d", &a);
        A[a] = 1;
        B[N / 2 - a - 1] = 1;
    }

    multiply(N, A, B);
    // for(int i = 0; i < N; i++) printf("%d ", A[i]); puts("");
    for(int i = 1; i <= XX; i++) {
        if(!A[N / 2 - 1 - i]) continue;
        int t = i + YY;
        for(int j = 1; j * t <= 500000; j++) ans[j * t] = 2 * t;
    }

    // for(int i = 0; i < 10; i++) printf("%d ", V[1][i]); puts("");

    scanf("%d", &Q);
    while(Q--) {
        int l; scanf("%d", &l);
        l /= 2;
        printf("%d ", ans[l] ? ans[l] : -1);
    }
    puts("");

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const ll P = 998244353, R = 3;

ll pw(ll x, ll y) {
    ll ret = 1;
    while(y) {
        if(y & 1) ret = ret * x % P;
        x = x * x % P;
        y >>= 1;
    }
    return ret;
}

void fft(int N, vector<ll>& a, bool f) {
    ll i, j, k, x, y, z;
    j = 0;
    for(i = 1; i < N; i++) {
        for(k = N >> 1; j >= k; k >>= 1) j -= k;
        j += k;
        if(i < j) {
            k = a[i];
            a[i] = a[j];
            a[j] = k;
        }
    }
    for(i = 1; i < N; i <<= 1) {
        x = pw(f ? pw(R, P - 2) : R, P / i >> 1);
        for(j = 0; j < N; j += i << 1) {
            y = 1;
            for(k = 0; k < i; k++) {
                z = a[i | j | k] * y % P;
                a[i | j | k] = a[j | k] - z;
                if(a[i | j | k] < 0) a[i | j | k] += P;
                a[j | k] += z;
                if(a[j | k] >= P) a[j | k] -= P;
                y = y * x % P;
            }
        }
    }
    if(f) {
        j = pw(N, P - 2);
        for(i = 0; i < N; i++) a[i] = a[i] * j % P;
    }
}

void multiply(int N, vector<ll>& X, vector<ll>& Y) {
    fft(N, X, false);
    fft(N, Y, false);
    for(int i = 0; i < N; i++) X[i] = X[i] * Y[i] % P;
    fft(N, X, true);
}

vector<ll> V[535353];
int A[202020];
bool chk[202020];
int M, XX, YY;
int ans;
int Q;

void dnc(int idx, int s, int e) {
    if(s == e) return;
    int len = (e - s);
    if(len == 1) {
        V[idx].resize(2);
        if(chk[s] && chk[e]) V[idx][1] = 1;
        return;
    }

    // printf("%d %d\n", s, e);

    int m = s + e >> 1;

    dnc(idx << 1, s, m);
    dnc(idx << 1 | 1, m, e);

    vector<ll> lft(len), rgt(len);
    int l = lower_bound(A + 1, A + M + 1, s) - A;
    int r = upper_bound(A + 1, A + M + 1, e) - A - 1;
    for(int i = l; i <= r; i++) {
        if(A[i] <= m) lft[m - A[i]] = 1;
        else rgt[A[i] - m] = 1;
    }

    multiply(len, lft, rgt);
    V[idx] = lft;
    for(int i = 0; i < len; i++) V[idx][i] = !!V[idx][i];

    for(int i = 0; i < len / 2; i++) {
        V[idx][i] |= V[idx << 1][i];
        V[idx][i] |= V[idx << 1 | 1][i];
    }
}

void check(int x) {
    if(x <= YY) return;
    if(V[1][x - YY]) {
        ans = max(ans, 2 * x);
    }
}

int main() {
    scanf("%d%d%d", &M, &XX, &YY);
    M++;
    for(int i = 1; i <= M; i++) {
        scanf("%d", &A[i]);
        chk[A[i]] = true;
    }
    dnc(1, 0, 262144);

    // for(int i = 0; i < 10; i++) printf("%d ", V[1][i]); puts("");

    scanf("%d", &Q);
    while(Q--) {
        int l; scanf("%d", &l);
        l /= 2;

        ans = 0;
        for(int i = 1; i * i <= l; i++) {
            if(l % i == 0) { check(i); check(l / i); }
        }
        printf("%d ", ans ? ans : -1);
    }
    puts("");

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const ll P = 998244353, R = 3;

int N = 32;

ll pw(ll x, ll y) {
    ll ret = 1;
    while(y) {
        if(y & 1) ret = ret * x % P;
        x = x * x % P;
        y >>= 1;
    }
    return ret;
}

void fft(int N, vector<ll>& a, bool f) {
    ll i, j, k, x, y, z;
    j = 0;
    for(i = 1; i < N; i++) {
        for(k = N >> 1; j >= k; k >>= 1) j -= k;
        j += k;
        if(i < j) {
            k = a[i];
            a[i] = a[j];
            a[j] = k;
        }
    }
    for(i = 1; i < N; i <<= 1) {
        x = pw(f ? pw(R, P - 2) : R, P / i >> 1);
        for(j = 0; j < N; j += i << 1) {
            y = 1;
            for(k = 0; k < i; k++) {
                z = a[i | j | k] * y % P;
                a[i | j | k] = a[j | k] - z;
                if(a[i | j | k] < 0) a[i | j | k] += P;
                a[j | k] += z;
                if(a[j | k] >= P) a[j | k] -= P;
                y = y * x % P;
            }
        }
    }
    if(f) {
        j = pw(N, P - 2);
        for(i = 0; i < N; i++) a[i] = a[i] * j % P;
    }
}

void multiply(int N, vector<ll>& X, vector<ll>& Y) {
    fft(N, X, false);
    fft(N, Y, false);
    for(int i = 0; i < N; i++) X[i] = X[i] * Y[i] % P;
    fft(N, X, true);
}

vector<ll> A(N), B(N);
int M, XX, YY;
int ans[505050];
int Q;

int main() {
    scanf("%d%d%d", &M, &XX, &YY);
    M++;
    for(int i = 1; i <= M; i++) {
        int a; scanf("%d", &a);
        A[a] = 1;
        B[N / 2 - a - 1] = 1;
    }

    multiply(N, A, B);
    // for(int i = 0; i < N; i++) printf("%d ", A[i]); puts("");
    for(int i = 1; i <= XX; i++) {
        if(!A[N / 2 - 1 - i]) continue;
        int t = i + YY;
        for(int j = 1; j * t <= 500000; j++) ans[j * t] = 2 * t;
    }

    // for(int i = 0; i < 10; i++) printf("%d ", V[1][i]); puts("");

    scanf("%d", &Q);
    while(Q--) {
        int l; scanf("%d", &l);
        l /= 2;
        printf("%d ", ans[l] ? ans[l] : -1);
    }
    puts("");

    return 0;
}


#include <cstdio>
#include <stack>
#include <set>
#include <cmath>
#include <map>
#include <time.h>
#include <vector>
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
//#include <memory.h>
#include <cstdlib>
#include <queue>
#include <iomanip>
#include <cassert>
#include <unordered_map>
#define P pair<int, int>
#define LL long long
#define LD long double
#define PLL pair<LL, LL>
#define mset(a, b) memset(a, b, sizeof(a))
#define rep(i, a, b) for (int i = a; i < b; i++)
#define PI acos(-1.0)
#define random(x) rand() % x
#define debug(x) cout << #x << " " << x << "\n"
using namespace std;
const int inf = 0x3f3f3f3f;
const LL __inf64 = 0x3f3f3f3f3f3f3f3f;
#ifdef DEBUG
const int MAX = 1e6 + 50;
#else
const int MAX = 1e6 + 500;
#endif
const int mod = 1e9 + 7;
void file_read() {
#ifdef DEBUG
	freopen("in", "r", stdin);
	// freopen("out", "w", stdout);
#endif
}

#include<complex>

const int K = 10;

int A[MAX];
complex<double> a[MAX], b[MAX];
int c[MAX];
int l[MAX];
bool vis[MAX];
int rev[MAX];
int ans[MAX];
vector<int> num;
void fft(complex<double> *a,  int n, int inv) {
	int bit = 0;
	while((1<<bit) < n) bit++;
	for(int i = 0; i < n; i++) {
		rev[i] = (rev[i>>1]>>1) | ((i & 1) << (bit-1));
		if(i < rev[i]) {
			swap(a[i], a[rev[i]]);
		}
	}
	for(int mid = 1; mid < n; mid <<= 1){
        complex<double> wn(cos(PI/mid), inv*sin(PI / mid));
        for(int i = 0; i < n; i += (mid<<1)){
            complex<double> w(1, 0);
            for(int j = 0; j < mid; j++, w *= wn){
                complex<double> u = a[i+j], t = w * a[i+j+mid];
                a[i+j] = u + t, a[i+j+mid] = u-t;
            }
        }
    }
}
int main() {
	file_read();
	mset(ans, -1);
	int n, x, y;
	scanf("%d%d%d", &n, &x, &y);
	int len1 = 0;
	int len2 = 0;
	for(int i = 1; i <= n+1; i++) {
		scanf("%d", &A[i]);
		a[A[i]] = complex<double>(1, 0);
		b[K-A[i]] = complex<double>(1, 0);
		len1 = max(len1, A[i]);
		len2 = max(len2, K-A[i]);
	}
	int N = 1;
	while(N <= len1+len2) N <<= 1;
	fft(a, N, 1); fft(b, N, 1);
	for(int i = 0; i <= N; i++) {
		a[i] *= b[i];
	}
	fft(a, N, -1);
	for(int i = 0; i <= N; i++) {
		c[i] = (int)(a[i].real() / N + 0.5);
		// printf("%d ", c[i]);
	}
	// puts("");
	for(int i = K+1; i <= N; i++) {
		if(c[i]) {
			num.push_back(i-K+y);
		}
	}
	#ifdef DEBUG
		for(auto x : num) printf("%d ", x);
		puts("");
	#endif
	int q;
	scanf("%d", &q);
	for(int i = 1; i <= q; i++) {
		scanf("%d", &l[i]);
		l[i] >>= 1;
	}
	for(auto x : num) {
		for(int i = x; i < MAX; i+=x) {
			ans[i] = max(ans[i], x);
		}
	}
	for(int i = 1; i <= q; i++) {
		printf("%d ", ans[l[i]] >= 0 ? (ans[l[i]] << 1) : -1);
	}
	return 0;
}


#include <cstdio>
#include <stack>
#include <set>
#include <cmath>
#include <map>
#include <time.h>
#include <vector>
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
//#include <memory.h>
#include <cstdlib>
#include <queue>
#include <iomanip>
#include <cassert>
#include <unordered_map>
#define P pair<int, int>
#define LL long long
#define LD long double
#define PLL pair<LL, LL>
#define mset(a, b) memset(a, b, sizeof(a))
#define rep(i, a, b) for (int i = a; i < b; i++)
#define PI acos(-1.0)
#define random(x) rand() % x
#define debug(x) cout << #x << " " << x << "\n"
using namespace std;
const int inf = 0x3f3f3f3f;
const LL __inf64 = 0x3f3f3f3f3f3f3f3f;
#ifdef DEBUG
const int MAX = 1e6 + 50;
#else
const int MAX = 1e6 + 500;
#endif
const int mod = 1e9 + 7;
void file_read() {
#ifdef DEBUG
	freopen("in", "r", stdin);
	// freopen("out", "w", stdout);
#endif
}

#include<complex>

const int K = 2e5;

int A[MAX];
complex<double> a[MAX], b[MAX];
int c[MAX];
int l[MAX];
bool vis[MAX];
int rev[MAX];
int ans[MAX];
vector<int> num;
void fft(complex<double> *a,  int n, int inv) {
	int bit = 0;
	while((1<<bit) < n) bit++;
	for(int i = 0; i < n; i++) {
		rev[i] = (rev[i>>1]>>1) | ((i & 1) << (bit-1));
		if(i < rev[i]) {
			swap(a[i], a[rev[i]]);
		}
	}
	for(int mid = 1; mid < n; mid <<= 1){
        complex<double> wn(cos(PI/mid), inv*sin(PI / mid));
        for(int i = 0; i < n; i += (mid<<1)){
            complex<double> w(1, 0);
            for(int j = 0; j < mid; j++, w *= wn){
                complex<double> u = a[i+j], t = w * a[i+j+mid];
                a[i+j] = u + t, a[i+j+mid] = u-t;
            }
        }
    }
}
int main() {
	file_read();
	mset(ans, -1);
	int n, x, y;
	scanf("%d%d%d", &n, &x, &y);
	int len1 = 0;
	int len2 = 0;
	for(int i = 1; i <= n+1; i++) {
		scanf("%d", &A[i]);
		a[A[i]] = complex<double>(1, 0);
		b[K-A[i]] = complex<double>(1, 0);
		len1 = max(len1, A[i]);
		len2 = max(len2, K-A[i]);
	}
	int N = 1;
	while(N <= len1+len2) N <<= 1;
	fft(a, N, 1); fft(b, N, 1);
	for(int i = 0; i <= N; i++) {
		a[i] *= b[i];
	}
	fft(a, N, -1);
	for(int i = 0; i <= N; i++) {
		c[i] = (int)(a[i].real() / N + 0.5);
		// printf("%d ", c[i]);
	}
	// puts("");
	for(int i = K+1; i <= N; i++) {
		if(c[i]) {
			num.push_back(i-K+y);
		}
	}
	#ifdef DEBUG
		for(auto x : num) printf("%d ", x);
		puts("");
	#endif
	int q;
	scanf("%d", &q);
	for(int i = 1; i <= q; i++) {
		scanf("%d", &l[i]);
		l[i] >>= 1;
	}
	for(auto x : num) {
		for(int i = x; i < MAX; i+=x) {
			ans[i] = max(ans[i], x);
		}
	}
	for(int i = 1; i <= q; i++) {
		printf("%d ", ans[l[i]] >= 0 ? (ans[l[i]] << 1) : -1);
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

void fft(vector<complex<double>> &a, bool invert) {
  int n = a.size();
  if (n == 1) return;

  vector<complex<double>> a0(n / 2), a1(n / 2);
  for (int i = 0; i < n / 2; i++) {
    a0[i] = a[2 * i];
    a1[i] = a[2 * i + 1];
  }
  fft(a0, invert);
  fft(a1, invert);

  double theta = 2 * acos(-1) / n * (invert ? -1 : 1);
  complex<double> w(1), wn(cos(theta), sin(theta));
  for (int i = 0; i < n / 2; i++) {
    a[i] = a0[i] + w * a1[i];
    a[i + n / 2] = a0[i] - w * a1[i];
    if (invert) {
      a[i] /= 2;
      a[i + n / 2] /= 2;
    }
    w *= wn;
  }
}

vector<int> mul(vector<int> &a, vector<int> &b) {
  vector<complex<double>> fa(a.begin(), a.end()), fb(b.begin(), b.end());
  int n = 1;
  while (n < a.size() + b.size()) n *= 2;
  fa.resize(n);
  fb.resize(n);

  fft(fa, false);
  fft(fb, false);
  vector<complex<double>> fc(n);
  for (int i = 0; i < n; i++) {
    fc[i] = fa[i] * fb[i];
  }
  fft(fc, true);

  vector<int> res(n);
  for (int i = 0; i < n; i++) {
    res[i] = round(fc[i].real());
  }
  return res;
}

int main() {
  ios_base::sync_with_stdio(false);

  int n, x, y;
  cin >> n >> x >> y;
  vector<int> a(n + 1);
  for (int i = 0; i < n + 1; i++) {
    cin >> a[i];
  }

  vector<int> p(x + 1), q(x + 1);
  for (auto i : a) {
    p[i] = 1;
    q[x - i] = 1;
  }
  auto f = mul(p, q);

  int qq, m;
  cin >> qq;
  while (qq--) {
    cin >> m;
    m /= 2;
    int ans = -1, want;
    for (int i = 1; i * i <= m; i++) {
      if (m % i == 0) {
        want = i - y;
        if (0 < want && want <= x && f[x + want] != 0) {
          ans = max(ans, 2 * (want + y));
        }
        want = m / i - y;
        if (0 < want && want <= x && f[x + want] != 0) {
          ans = max(ans, 2 * (want + y));
        }
      }
    }
    cout << ans << ' ';
  }
  cout << '\n';

  return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

// #define int           long long
#define S             second
#define F             first
#define pb            push_back
#define all(c)        (c).begin(),(c).end()
#define rall(c)       (c).rbegin(),(c).rend()
#define lb            lower_bound
#define ub            upper_bound
#define si(c)         (int)((c).size())
#define lcm(a, b)      (a * (b / __gcd(a,b)))
#define inf           (int)(4e18)
#define endl          '\n'
#define mp            make_pair
#define time(s)       (double(clock()-s)/double(CLOCKS_PER_SEC))
#define debug(args...)    _F(#args, args)
#define vi            std::vector<int>
#define pii           pair<int, int>
#define vpi           vector<pii>
#define ordered_set   tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T> void _F(const char *name, T arg1){ cerr << name << " = " << arg1 << endl;}
template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args)
{ const char *name = strchr(names, ',');cerr.write(names, name-names) << " = " << arg1 << endl;_F(name+2, args...);}

template< typename T1, typename T2 > istream& operator>>(istream& in, pair<T1, T2> &q){ in >> q.F >> q.S; return in;}
template< typename T1, typename T2 > ostream& operator<<(ostream& out, pair<T1, T2> &q){ out << q.F << " " << q.S; return out;}
template< typename T1, typename T2 > pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F+p2.F, p1.S+p2.S};}
template< typename T1, typename T2 > pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F-p2.F, p1.S-p2.S};}
template< typename T1, typename T2 > bool operator<(pair<T1, T2> p1, pair<T1, T2> p2){ return p1 < p2 ;}

template<typename T> void Unique(vector<T> &v) {
    sort(all(v)), v.resize(distance(v.begin(), unique(all(v))));
}

const int N = 2e5+1;

using cd = complex<double>;
const double PI = acos(-1);

std::vector<int> a(N);
std::vector<int> b(N);
std::vector<int> pre(N*10);
std::vector<int> dp(N*10);

void fft(vector<cd> & a, bool invert) {
    int n = a.size();
    if (n == 1)
        return;

    vector<cd> a0(n / 2), a1(n / 2);
    for (int i = 0; 2 * i < n; i++) {
        a0[i] = a[2*i];
        a1[i] = a[2*i+1];
    }
    fft(a0, invert);
    fft(a1, invert);

    double ang = 2 * PI / n * (invert ? -1 : 1);
    cd w(1), wn(cos(ang), sin(ang));
    for (int i = 0; 2 * i < n; i++) {
        a[i] = a0[i] + w * a1[i];
        a[i + n/2] = a0[i] - w * a1[i];
        if (invert) {
            a[i] /= 2;
            a[i + n/2] /= 2;
        }
        w *= wn;
    }
}

vector<int> multiply(vector<int> const& a, vector<int> const& b) {
    vector<cd> fa(a.begin(), a.end()), fb(b.begin(), b.end());
    int n = 1;
    while (n < a.size() + b.size())
        n <<= 1;
    fa.resize(n);
    fb.resize(n);

    fft(fa, false);
    fft(fb, false);
    for (int i = 0; i < n; i++)
        fa[i] *= fb[i];
    fft(fa, true);

    vector<int> result(n);
    for (int i = 0; i < n; i++)
        result[i] = round(fa[i].real());
    return result;
}

void solve() {
	int n, x, y;
	cin >> n >> x >> y;

	for(int i = 0; i < n+1; i++) {
		int x; cin >> x;
		a[x] = 1;
		b[N-1-x] = 1;
	}

	std::vector<int> v = multiply(a, b);

	for(int i = N; i < si(v); i++) {
		if(v[i])pre[i-N+1+y] = 1;
	}

	for(int i = 1; i < N*2; i++) {
		if(pre[i]) {
			for(int j = i; j < N*10; j += i)
				dp[j] = max(dp[j], i);
		}
	}
	int q; cin >> q;
	while(q--) {
		int l; cin >> l;
		l /= 2;
		if(dp[l]) {
			cout << dp[l]*2 << " ";
		}
		else
			cout << -1 << " ";
		// cout << max(dp[l]*2, -1) << " ";
	}
}

signed main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    start = clock();

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif

    int test = 1;
    // cin >> test;

    cout << fixed << setprecision(2);

    for(int i = 1; i <= test; ++i){
    	solve();
    }

    cerr << time(start);
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

// #define int           long long
#define S             second
#define F             first
#define pb            push_back
#define all(c)        (c).begin(),(c).end()
#define rall(c)       (c).rbegin(),(c).rend()
#define lb            lower_bound
#define ub            upper_bound
#define si(c)         (int)((c).size())
#define lcm(a, b)      (a * (b / __gcd(a,b)))
#define inf           (int)(4e18)
#define endl          '\n'
#define mp            make_pair
#define time(s)       (double(clock()-s)/double(CLOCKS_PER_SEC))
#define debug(args...)    _F(#args, args)
#define vi            std::vector<int>
#define pii           pair<int, int>
#define vpi           vector<pii>
#define ordered_set   tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T> void _F(const char *name, T arg1){ cerr << name << " = " << arg1 << endl;}
template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args)
{ const char *name = strchr(names, ',');cerr.write(names, name-names) << " = " << arg1 << endl;_F(name+2, args...);}

template< typename T1, typename T2 > istream& operator>>(istream& in, pair<T1, T2> &q){ in >> q.F >> q.S; return in;}
template< typename T1, typename T2 > ostream& operator<<(ostream& out, pair<T1, T2> &q){ out << q.F << " " << q.S; return out;}
template< typename T1, typename T2 > pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F+p2.F, p1.S+p2.S};}
template< typename T1, typename T2 > pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F-p2.F, p1.S-p2.S};}
template< typename T1, typename T2 > bool operator<(pair<T1, T2> p1, pair<T1, T2> p2){ return p1 < p2 ;}

template<typename T> void Unique(vector<T> &v) {
    sort(all(v)), v.resize(distance(v.begin(), unique(all(v))));
}

const int N = 2e5+1;

using cd = complex<double>;
const double PI = acos(-1);

std::vector<int> a(N);
std::vector<int> b(N);
std::vector<int> pre(N*10);
std::vector<int> dp(N*10, -1);

void fft(vector<cd> & a, bool invert) {
    int n = a.size();
    if (n == 1)
        return;

    vector<cd> a0(n / 2), a1(n / 2);
    for (int i = 0; 2 * i < n; i++) {
        a0[i] = a[2*i];
        a1[i] = a[2*i+1];
    }
    fft(a0, invert);
    fft(a1, invert);

    double ang = 2 * PI / n * (invert ? -1 : 1);
    cd w(1), wn(cos(ang), sin(ang));
    for (int i = 0; 2 * i < n; i++) {
        a[i] = a0[i] + w * a1[i];
        a[i + n/2] = a0[i] - w * a1[i];
        if (invert) {
            a[i] /= 2;
            a[i + n/2] /= 2;
        }
        w *= wn;
    }
}

vector<int> multiply(vector<int> const& a, vector<int> const& b) {
    vector<cd> fa(a.begin(), a.end()), fb(b.begin(), b.end());
    int n = 1;
    while (n < a.size() + b.size())
        n <<= 1;
    fa.resize(n);
    fb.resize(n);

    fft(fa, false);
    fft(fb, false);
    for (int i = 0; i < n; i++)
        fa[i] *= fb[i];
    fft(fa, true);

    vector<int> result(n);
    for (int i = 0; i < n; i++)
        result[i] = round(fa[i].real());
    return result;
}

void solve() {
	int n, x, y;
	cin >> n >> x >> y;

	for(int i = 0; i < n+1; i++) {
		int x; cin >> x;
		a[x] = 1;
		b[N-1-x] = 1;
	}

	std::vector<int> v = multiply(a, b);

	for(int i = N; i < si(v); i++) {
		if(v[i])pre[i-N+1+y] = 1;
	}

	for(int i = 1; i < N*2; i++) {
		if(pre[i]) {
			for(int j = i; j < N*10; j += i)
				dp[j] = max(dp[j], i);
		}
	}
	int q; cin >> q;
	while(q--) {
		int l; cin >> l;
		l /= 2;
		cout << max(dp[l]*2, -1) << " ";
	}
}

signed main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    start = clock();

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif

    int test = 1;
    // cin >> test;

    cout << fixed << setprecision(2);

    for(int i = 1; i <= test; ++i){
    	solve();
    }

    cerr << time(start);
    return 0;
}
w


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define int           long long
#define S             second
#define F             first
#define pb            push_back
#define all(c)        (c).begin(),(c).end()
#define rall(c)       (c).rbegin(),(c).rend()
#define lb            lower_bound
#define ub            upper_bound
#define si(c)         (int)((c).size())
#define lcm(a, b)      (a * (b / __gcd(a,b)))
#define inf           (int)(4e18)
#define endl          '\n'
#define mp            make_pair
#define time(s)       (double(clock()-s)/double(CLOCKS_PER_SEC))
#define debug(args...)    _F(#args, args)
#define vi            std::vector<int>
#define pii           pair<int, int>
#define vpi           vector<pii>
#define ordered_set   tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T> void _F(const char *name, T arg1){ cerr << name << " = " << arg1 << endl;}
template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args)
{ const char *name = strchr(names, ',');cerr.write(names, name-names) << " = " << arg1 << endl;_F(name+2, args...);}

template< typename T1, typename T2 > istream& operator>>(istream& in, pair<T1, T2> &q){ in >> q.F >> q.S; return in;}
template< typename T1, typename T2 > ostream& operator<<(ostream& out, pair<T1, T2> &q){ out << q.F << " " << q.S; return out;}
template< typename T1, typename T2 > pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F+p2.F, p1.S+p2.S};}
template< typename T1, typename T2 > pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F-p2.F, p1.S-p2.S};}
template< typename T1, typename T2 > bool operator<(pair<T1, T2> p1, pair<T1, T2> p2){ return p1 < p2 ;}

template<typename T> void Unique(vector<T> &v) {
    sort(all(v)), v.resize(distance(v.begin(), unique(all(v))));
}

const int N = 2e5+1;

using cd = complex<double>;
const double PI = acos(-1);

std::vector<int> a(N);
std::vector<int> b(N);
std::vector<int> pre(N*10);
std::vector<int> dp(N*10, -1);

void fft(vector<cd> & a, bool invert) {
    int n = a.size();
    if (n == 1)
        return;

    vector<cd> a0(n / 2), a1(n / 2);
    for (int i = 0; 2 * i < n; i++) {
        a0[i] = a[2*i];
        a1[i] = a[2*i+1];
    }
    fft(a0, invert);
    fft(a1, invert);

    double ang = 2 * PI / n * (invert ? -1 : 1);
    cd w(1), wn(cos(ang), sin(ang));
    for (int i = 0; 2 * i < n; i++) {
        a[i] = a0[i] + w * a1[i];
        a[i + n/2] = a0[i] - w * a1[i];
        if (invert) {
            a[i] /= 2;
            a[i + n/2] /= 2;
        }
        w *= wn;
    }
}

vector<int> multiply(vector<int> const& a, vector<int> const& b) {
    vector<cd> fa(a.begin(), a.end()), fb(b.begin(), b.end());
    int n = 1;
    while (n < a.size() + b.size())
        n <<= 1;
    fa.resize(n);
    fb.resize(n);

    fft(fa, false);
    fft(fb, false);
    for (int i = 0; i < n; i++)
        fa[i] *= fb[i];
    fft(fa, true);

    vector<int> result(n);
    for (int i = 0; i < n; i++)
        result[i] = round(fa[i].real());
    return result;
}

void solve() {
	int n, x, y;
	cin >> n >> x >> y;

	for(int i = 0; i < n+1; i++) {
		int x; cin >> x;
		a[x] = 1;
		b[N-1-x] = 1;
	}

	std::vector<int> v = multiply(a, b);

	for(int i = N; i < si(v); i++) {
		if(v[i])pre[i-N+1+y] = 1;
	}

	for(int i = 1; i < N*2; i++) {
		if(pre[i]) {
			for(int j = i; j < N*10; j += i)
				dp[j] = max(dp[j], i);
		}
	}
	int q; cin >> q;
	while(q--) {
		int l; cin >> l;
		l /= 2;
		cout << max(dp[l]*2, -1LL) << " ";
	}
}

signed main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    start = clock();

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif

    int test = 1;
    // cin >> test;

    cout << fixed << setprecision(2);

    for(int i = 1; i <= test; ++i){
    	solve();
    }

    cerr << time(start);
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

// #define int           long long
#define S             second
#define F             first
#define pb            push_back
#define all(c)        (c).begin(),(c).end()
#define rall(c)       (c).rbegin(),(c).rend()
#define lb            lower_bound
#define ub            upper_bound
#define si(c)         (int)((c).size())
#define lcm(a, b)      (a * (b / __gcd(a,b)))
#define inf           (int)(4e18)
#define endl          '\n'
#define mp            make_pair
#define time(s)       (double(clock()-s)/double(CLOCKS_PER_SEC))
#define debug(args...)    _F(#args, args)
#define vi            std::vector<int>
#define pii           pair<int, int>
#define vpi           vector<pii>
#define ordered_set   tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T> void _F(const char *name, T arg1){ cerr << name << " = " << arg1 << endl;}
template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args)
{ const char *name = strchr(names, ',');cerr.write(names, name-names) << " = " << arg1 << endl;_F(name+2, args...);}

template< typename T1, typename T2 > istream& operator>>(istream& in, pair<T1, T2> &q){ in >> q.F >> q.S; return in;}
template< typename T1, typename T2 > ostream& operator<<(ostream& out, pair<T1, T2> &q){ out << q.F << " " << q.S; return out;}
template< typename T1, typename T2 > pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F+p2.F, p1.S+p2.S};}
template< typename T1, typename T2 > pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F-p2.F, p1.S-p2.S};}
template< typename T1, typename T2 > bool operator<(pair<T1, T2> p1, pair<T1, T2> p2){ return p1 < p2 ;}

template<typename T> void Unique(vector<T> &v) {
    sort(all(v)), v.resize(distance(v.begin(), unique(all(v))));
}

const int N = 2e5+1;

using cd = complex<double>;
const double PI = acos(-1);

std::vector<int> a(N);
std::vector<int> b(N);
std::vector<int> pre(N*10);
std::vector<int> dp(N*10, -1);

void fft(vector<cd> & a, bool invert) {
    int n = a.size();
    if (n == 1)
        return;

    vector<cd> a0(n / 2), a1(n / 2);
    for (int i = 0; 2 * i < n; i++) {
        a0[i] = a[2*i];
        a1[i] = a[2*i+1];
    }
    fft(a0, invert);
    fft(a1, invert);

    double ang = 2 * PI / n * (invert ? -1 : 1);
    cd w(1), wn(cos(ang), sin(ang));
    for (int i = 0; 2 * i < n; i++) {
        a[i] = a0[i] + w * a1[i];
        a[i + n/2] = a0[i] - w * a1[i];
        if (invert) {
            a[i] /= 2;
            a[i + n/2] /= 2;
        }
        w *= wn;
    }
}

vector<int> multiply(vector<int> const& a, vector<int> const& b) {
    vector<cd> fa(a.begin(), a.end()), fb(b.begin(), b.end());
    int n = 1;
    while (n < a.size() + b.size())
        n <<= 1;
    fa.resize(n);
    fb.resize(n);

    fft(fa, false);
    fft(fb, false);
    for (int i = 0; i < n; i++)
        fa[i] *= fb[i];
    fft(fa, true);

    vector<int> result(n);
    for (int i = 0; i < n; i++)
        result[i] = round(fa[i].real());
    return result;
}

void solve() {
	int n, x, y;
	cin >> n >> x >> y;

	for(int i = 0; i < n+1; i++) {
		int x; cin >> x;
		a[x] = 1;
		b[N-1-x] = 1;
	}

	std::vector<int> v = multiply(a, b);

	for(int i = N; i < si(v); i++) {
		if(v[i])pre[i-N+1+y] = 1;
	}

	for(int i = 1; i < N*2; i++) {
		if(pre[i]) {
			for(int j = i; j < N*10; j += i)
				dp[j] = max(dp[j], i);
		}
	}
	int q; cin >> q;
	while(q--) {
		int l; cin >> l;
		l /= 2;
		cout << max(dp[l]*2, -1LL) << " ";
	}
}

signed main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    start = clock();

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif

    int test = 1;
    // cin >> test;

    cout << fixed << setprecision(2);

    for(int i = 1; i <= test; ++i){
    	solve();
    }

    cerr << time(start);
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

// #define int           long long
#define S             second
#define F             first
#define pb            push_back
#define all(c)        (c).begin(),(c).end()
#define rall(c)       (c).rbegin(),(c).rend()
#define lb            lower_bound
#define ub            upper_bound
#define si(c)         (int)((c).size())
#define lcm(a, b)      (a * (b / __gcd(a,b)))
#define inf           (int)(4e18)
#define endl          '\n'
#define mp            make_pair
#define time(s)       (double(clock()-s)/double(CLOCKS_PER_SEC))
#define debug(args...)    _F(#args, args)
#define vi            std::vector<int>
#define pii           pair<int, int>
#define vpi           vector<pii>
#define ordered_set   tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T> void _F(const char *name, T arg1){ cerr << name << " = " << arg1 << endl;}
template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args)
{ const char *name = strchr(names, ',');cerr.write(names, name-names) << " = " << arg1 << endl;_F(name+2, args...);}

template< typename T1, typename T2 > istream& operator>>(istream& in, pair<T1, T2> &q){ in >> q.F >> q.S; return in;}
template< typename T1, typename T2 > ostream& operator<<(ostream& out, pair<T1, T2> &q){ out << q.F << " " << q.S; return out;}
template< typename T1, typename T2 > pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F+p2.F, p1.S+p2.S};}
template< typename T1, typename T2 > pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F-p2.F, p1.S-p2.S};}
template< typename T1, typename T2 > bool operator<(pair<T1, T2> p1, pair<T1, T2> p2){ return p1 < p2 ;}

template<typename T> void Unique(vector<T> &v) {
    sort(all(v)), v.resize(distance(v.begin(), unique(all(v))));
}

const int N = 2e5+1;

using cd = complex<double>;
const double PI = acos(-1);

std::vector<int> a(N);
std::vector<int> b(N);
std::vector<int> pre(N*10);
std::vector<int> dp(N*10);

void fft(vector<cd> & a, bool invert) {
    int n = a.size();
    if (n == 1)
        return;

    vector<cd> a0(n / 2), a1(n / 2);
    for (int i = 0; 2 * i < n; i++) {
        a0[i] = a[2*i];
        a1[i] = a[2*i+1];
    }
    fft(a0, invert);
    fft(a1, invert);

    double ang = 2 * PI / n * (invert ? -1 : 1);
    cd w(1), wn(cos(ang), sin(ang));
    for (int i = 0; 2 * i < n; i++) {
        a[i] = a0[i] + w * a1[i];
        a[i + n/2] = a0[i] - w * a1[i];
        if (invert) {
            a[i] /= 2;
            a[i + n/2] /= 2;
        }
        w *= wn;
    }
}

vector<int> multiply(vector<int> const& a, vector<int> const& b) {
    vector<cd> fa(a.begin(), a.end()), fb(b.begin(), b.end());
    int n = 1;
    while (n < a.size() + b.size())
        n <<= 1;
    fa.resize(n);
    fb.resize(n);

    fft(fa, false);
    fft(fb, false);
    for (int i = 0; i < n; i++)
        fa[i] *= fb[i];
    fft(fa, true);

    vector<int> result(n);
    for (int i = 0; i < n; i++)
        result[i] = round(fa[i].real());
    return result;
}

void solve() {
	int n, x, y;
	cin >> n >> x >> y;

	for(int i = 0; i < n+1; i++) {
		int x; cin >> x;
		a[x] = 1;
		b[N-1-x] = 1;
	}

	std::vector<int> v = multiply(a, b);

	for(int i = N; i < si(v); i++) {
		if(v[i])pre[i-N+1+y] = 1;
	}

	for(int i = 1; i < N*2; i++) {
		if(pre[i]) {
			for(int j = i; j < N*10; j += i)
				dp[j] = max(dp[j], i*2);
		}
	}
	int q; cin >> q;
	while(q--) {
		int l; cin >> l;
		l /= 2;
		cout << dp[l] << " ";
	}
}

signed main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    start = clock();

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif

    int test = 1;
    // cin >> test;

    cout << fixed << setprecision(2);

    for(int i = 1; i <= test; ++i){
    	solve();
    }

    cerr << time(start);
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define int           long long
#define S             second
#define F             first
#define pb            push_back
#define all(c)        (c).begin(),(c).end()
#define rall(c)       (c).rbegin(),(c).rend()
#define lb            lower_bound
#define ub            upper_bound
#define si(c)         (int)((c).size())
#define lcm(a, b)      (a * (b / __gcd(a,b)))
#define inf           (int)(4e18)
#define endl          '\n'
#define mp            make_pair
#define time(s)       (double(clock()-s)/double(CLOCKS_PER_SEC))
#define debug(args...)    _F(#args, args)
#define vi            std::vector<int>
#define pii           pair<int, int>
#define vpi           vector<pii>
#define ordered_set   tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T> void _F(const char *name, T arg1){ cerr << name << " = " << arg1 << endl;}
template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args)
{ const char *name = strchr(names, ',');cerr.write(names, name-names) << " = " << arg1 << endl;_F(name+2, args...);}

template< typename T1, typename T2 > istream& operator>>(istream& in, pair<T1, T2> &q){ in >> q.F >> q.S; return in;}
template< typename T1, typename T2 > ostream& operator<<(ostream& out, pair<T1, T2> &q){ out << q.F << " " << q.S; return out;}
template< typename T1, typename T2 > pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F+p2.F, p1.S+p2.S};}
template< typename T1, typename T2 > pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F-p2.F, p1.S-p2.S};}
template< typename T1, typename T2 > bool operator<(pair<T1, T2> p1, pair<T1, T2> p2){ return p1 < p2 ;}

template<typename T> void Unique(vector<T> &v) {
    sort(all(v)), v.resize(distance(v.begin(), unique(all(v))));
}

const int N = 2e5+1;

using cd = complex<double>;
const double PI = acos(-1);

std::vector<int> a(N);
std::vector<int> b(N);
std::vector<int> pre(N*10);
std::vector<int> dp(N*10, -1);

void fft(vector<cd> & a, bool invert) {
    int n = a.size();
    if (n == 1)
        return;

    vector<cd> a0(n / 2), a1(n / 2);
    for (int i = 0; 2 * i < n; i++) {
        a0[i] = a[2*i];
        a1[i] = a[2*i+1];
    }
    fft(a0, invert);
    fft(a1, invert);

    double ang = 2 * PI / n * (invert ? -1 : 1);
    cd w(1), wn(cos(ang), sin(ang));
    for (int i = 0; 2 * i < n; i++) {
        a[i] = a0[i] + w * a1[i];
        a[i + n/2] = a0[i] - w * a1[i];
        if (invert) {
            a[i] /= 2;
            a[i + n/2] /= 2;
        }
        w *= wn;
    }
}

vector<int> multiply(vector<int> const& a, vector<int> const& b) {
    vector<cd> fa(a.begin(), a.end()), fb(b.begin(), b.end());
    int n = 1;
    while (n < a.size() + b.size())
        n <<= 1;
    fa.resize(n);
    fb.resize(n);

    fft(fa, false);
    fft(fb, false);
    for (int i = 0; i < n; i++)
        fa[i] *= fb[i];
    fft(fa, true);

    vector<int> result(n);
    for (int i = 0; i < n; i++)
        result[i] = round(fa[i].real());
    return result;
}

void solve() {
	int n, x, y;
	cin >> n >> x >> y;

	for(int i = 0; i < n+1; i++) {
		int x; cin >> x;
		a[x] = 1;
		b[N-1-x] = 1;
	}

	std::vector<int> v = multiply(a, b);

	for(int i = N; i < si(v); i++) {
		if(v[i])pre[(i-N+1+y)*2] = 1;
	}

	for(int i = 1; i < N*2; i++) {
		if(pre[i]) {
			// cout << i << endl;
			for(int j = i; j < N*10; j += i)
				dp[j] = max(dp[j], i);
		}
	}
	int q; cin >> q;
	while(q--) {
		int l; cin >> l;
		cout << dp[l] << " ";
	}
}

signed main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    start = clock();

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif

    int test = 1;
    // cin >> test;

    cout << fixed << setprecision(2);

    for(int i = 1; i <= test; ++i){
    	solve();
    }

    cerr << time(start);
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

// #define int           long long
#define S             second
#define F             first
#define pb            push_back
#define all(c)        (c).begin(),(c).end()
#define rall(c)       (c).rbegin(),(c).rend()
#define lb            lower_bound
#define ub            upper_bound
#define si(c)         (int)((c).size())
#define lcm(a, b)      (a * (b / __gcd(a,b)))
#define inf           (int)(4e18)
#define endl          '\n'
#define mp            make_pair
#define time(s)       (double(clock()-s)/double(CLOCKS_PER_SEC))
#define debug(args...)    _F(#args, args)
#define vi            std::vector<int>
#define pii           pair<int, int>
#define vpi           vector<pii>
#define ordered_set   tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T> void _F(const char *name, T arg1){ cerr << name << " = " << arg1 << endl;}
template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args)
{ const char *name = strchr(names, ',');cerr.write(names, name-names) << " = " << arg1 << endl;_F(name+2, args...);}

template< typename T1, typename T2 > istream& operator>>(istream& in, pair<T1, T2> &q){ in >> q.F >> q.S; return in;}
template< typename T1, typename T2 > ostream& operator<<(ostream& out, pair<T1, T2> &q){ out << q.F << " " << q.S; return out;}
template< typename T1, typename T2 > pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F+p2.F, p1.S+p2.S};}
template< typename T1, typename T2 > pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F-p2.F, p1.S-p2.S};}
template< typename T1, typename T2 > bool operator<(pair<T1, T2> p1, pair<T1, T2> p2){ return p1 < p2 ;}

template<typename T> void Unique(vector<T> &v) {
    sort(all(v)), v.resize(distance(v.begin(), unique(all(v))));
}

const int N = 2e5+1;

using cd = complex<double>;
const double PI = acos(-1);

std::vector<int> a(N);
std::vector<int> b(N);
std::vector<int> pre(N*10);
std::vector<int> dp(N*10, -1);

void fft(vector<cd> & a, bool invert) {
    int n = a.size();
    if (n == 1)
        return;

    vector<cd> a0(n / 2), a1(n / 2);
    for (int i = 0; 2 * i < n; i++) {
        a0[i] = a[2*i];
        a1[i] = a[2*i+1];
    }
    fft(a0, invert);
    fft(a1, invert);

    double ang = 2 * PI / n * (invert ? -1 : 1);
    cd w(1), wn(cos(ang), sin(ang));
    for (int i = 0; 2 * i < n; i++) {
        a[i] = a0[i] + w * a1[i];
        a[i + n/2] = a0[i] - w * a1[i];
        if (invert) {
            a[i] /= 2;
            a[i + n/2] /= 2;
        }
        w *= wn;
    }
}

vector<int> multiply(vector<int> const& a, vector<int> const& b) {
    vector<cd> fa(a.begin(), a.end()), fb(b.begin(), b.end());
    int n = 1;
    while (n < a.size() + b.size())
        n <<= 1;
    fa.resize(n);
    fb.resize(n);

    fft(fa, false);
    fft(fb, false);
    for (int i = 0; i < n; i++)
        fa[i] *= fb[i];
    fft(fa, true);

    vector<int> result(n);
    for (int i = 0; i < n; i++)
        result[i] = round(fa[i].real());
    return result;
}

void solve() {
	int n, x, y;
	cin >> n >> x >> y;

	for(int i = 0; i < n+1; i++) {
		int x; cin >> x;
		a[x] = 1;
		b[N-1-x] = 1;
	}

	std::vector<int> v = multiply(a, b);

	for(int i = N; i < si(v); i++) {
		if(v[i])pre[(i-N+1+y)*2] = 1;
	}

	for(int i = 1; i < N*10; i++) {
		if(pre[i]) {
			// cout << i << endl;
			for(int j = i; j < N*10; j += i)
				dp[j] = max(dp[j], i);
		}
	}
	int q; cin >> q;
	while(q--) {
		int l; cin >> l;
		cout << dp[l] << " ";
	}
}

signed main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    start = clock();

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif

    int test = 1;
    // cin >> test;

    cout << fixed << setprecision(2);

    for(int i = 1; i <= test; ++i){
    	solve();
    }

    cerr << time(start);
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

// #define int           long long
#define S             second
#define F             first
#define pb            push_back
#define all(c)        (c).begin(),(c).end()
#define rall(c)       (c).rbegin(),(c).rend()
#define lb            lower_bound
#define ub            upper_bound
#define si(c)         (int)((c).size())
#define lcm(a, b)      (a * (b / __gcd(a,b)))
#define inf           (int)(4e18)
#define endl          '\n'
#define mp            make_pair
#define time(s)       (double(clock()-s)/double(CLOCKS_PER_SEC))
#define debug(args...)    _F(#args, args)
#define vi            std::vector<int>
#define pii           pair<int, int>
#define vpi           vector<pii>
#define ordered_set   tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T> void _F(const char *name, T arg1){ cerr << name << " = " << arg1 << endl;}
template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args)
{ const char *name = strchr(names, ',');cerr.write(names, name-names) << " = " << arg1 << endl;_F(name+2, args...);}

template< typename T1, typename T2 > istream& operator>>(istream& in, pair<T1, T2> &q){ in >> q.F >> q.S; return in;}
template< typename T1, typename T2 > ostream& operator<<(ostream& out, pair<T1, T2> &q){ out << q.F << " " << q.S; return out;}
template< typename T1, typename T2 > pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F+p2.F, p1.S+p2.S};}
template< typename T1, typename T2 > pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F-p2.F, p1.S-p2.S};}
template< typename T1, typename T2 > bool operator<(pair<T1, T2> p1, pair<T1, T2> p2){ return p1 < p2 ;}

template<typename T> void Unique(vector<T> &v) {
    sort(all(v)), v.resize(distance(v.begin(), unique(all(v))));
}

const int N = 2e5+1;

using cd = complex<double>;
const double PI = acos(-1);

std::vector<int> a(N);
std::vector<int> b(N);
std::vector<int> pre(N*10);
std::vector<int> dp(N*10, -1);

void fft(vector<cd> & a, bool invert) {
    int n = a.size();
    if (n == 1)
        return;

    vector<cd> a0(n / 2), a1(n / 2);
    for (int i = 0; 2 * i < n; i++) {
        a0[i] = a[2*i];
        a1[i] = a[2*i+1];
    }
    fft(a0, invert);
    fft(a1, invert);

    double ang = 2 * PI / n * (invert ? -1 : 1);
    cd w(1), wn(cos(ang), sin(ang));
    for (int i = 0; 2 * i < n; i++) {
        a[i] = a0[i] + w * a1[i];
        a[i + n/2] = a0[i] - w * a1[i];
        if (invert) {
            a[i] /= 2;
            a[i + n/2] /= 2;
        }
        w *= wn;
    }
}

vector<int> multiply(vector<int> const& a, vector<int> const& b) {
    vector<cd> fa(a.begin(), a.end()), fb(b.begin(), b.end());
    int n = 1;
    while (n < a.size() + b.size())
        n <<= 1;
    fa.resize(n);
    fb.resize(n);

    fft(fa, false);
    fft(fb, false);
    for (int i = 0; i < n; i++)
        fa[i] *= fb[i];
    fft(fa, true);

    vector<int> result(n);
    for (int i = 0; i < n; i++)
        result[i] = round(fa[i].real());
    return result;
}

void solve() {
	int n, x, y;
	cin >> n >> x >> y;

	for(int i = 0; i < n+1; i++) {
		int x; cin >> x;
		a[x] = 1;
		b[N-1-x] = 1;
	}

	std::vector<int> v = multiply(a, b);

	for(int i = N; i < si(v); i++) {
		if(v[i])pre[i-N+1+y] = 1;
	}

	for(int i = 1; i < N*2; i++) {
		if(pre[i]) {
			for(int j = i; j < N*10; j += i)
				dp[j] = max(dp[j], i);
		}
	}
	int q; cin >> q;
	while(q--) {
		int l; cin >> l;
		l /= 2;
		cout << max(dp[l]*2, -1) << " ";
	}
}

signed main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    start = clock();

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif

    int test = 1;
    // cin >> test;

    cout << fixed << setprecision(2);

    for(int i = 1; i <= test; ++i){
    	solve();
    }

    cerr << time(start);
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

// #define int           long long
#define S             second
#define F             first
#define pb            push_back
#define all(c)        (c).begin(),(c).end()
#define rall(c)       (c).rbegin(),(c).rend()
#define lb            lower_bound
#define ub            upper_bound
#define si(c)         (int)((c).size())
#define lcm(a, b)      (a * (b / __gcd(a,b)))
#define inf           (int)(4e18)
#define endl          '\n'
#define mp            make_pair
#define time(s)       (double(clock()-s)/double(CLOCKS_PER_SEC))
#define debug(args...)    _F(#args, args)
#define vi            std::vector<int>
#define pii           pair<int, int>
#define vpi           vector<pii>
#define ordered_set   tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T> void _F(const char *name, T arg1){ cerr << name << " = " << arg1 << endl;}
template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args)
{ const char *name = strchr(names, ',');cerr.write(names, name-names) << " = " << arg1 << endl;_F(name+2, args...);}

template< typename T1, typename T2 > istream& operator>>(istream& in, pair<T1, T2> &q){ in >> q.F >> q.S; return in;}
template< typename T1, typename T2 > ostream& operator<<(ostream& out, pair<T1, T2> &q){ out << q.F << " " << q.S; return out;}
template< typename T1, typename T2 > pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F+p2.F, p1.S+p2.S};}
template< typename T1, typename T2 > pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F-p2.F, p1.S-p2.S};}
template< typename T1, typename T2 > bool operator<(pair<T1, T2> p1, pair<T1, T2> p2){ return p1 < p2 ;}

template<typename T> void Unique(vector<T> &v) {
    sort(all(v)), v.resize(distance(v.begin(), unique(all(v))));
}

const int N = 2e5+1;

using cd = complex<double>;
const double PI = acos(-1);

std::vector<int> a(N);
std::vector<int> b(N);
std::vector<int> pre(N*10);
std::vector<int> dp(N*10, -1);

void fft(vector<cd> & a, bool invert) {
    int n = a.size();
    if (n == 1)
        return;

    vector<cd> a0(n / 2), a1(n / 2);
    for (int i = 0; 2 * i < n; i++) {
        a0[i] = a[2*i];
        a1[i] = a[2*i+1];
    }
    fft(a0, invert);
    fft(a1, invert);

    double ang = 2 * PI / n * (invert ? -1 : 1);
    cd w(1), wn(cos(ang), sin(ang));
    for (int i = 0; 2 * i < n; i++) {
        a[i] = a0[i] + w * a1[i];
        a[i + n/2] = a0[i] - w * a1[i];
        if (invert) {
            a[i] /= 2;
            a[i + n/2] /= 2;
        }
        w *= wn;
    }
}

vector<int> multiply(vector<int> const& a, vector<int> const& b) {
    vector<cd> fa(a.begin(), a.end()), fb(b.begin(), b.end());
    int n = 1;
    while (n < a.size() + b.size())
        n <<= 1;
    fa.resize(n);
    fb.resize(n);

    fft(fa, false);
    fft(fb, false);
    for (int i = 0; i < n; i++)
        fa[i] *= fb[i];
    fft(fa, true);

    vector<int> result(n);
    for (int i = 0; i < n; i++)
        result[i] = round(fa[i].real());
    return result;
}

void solve() {
	int n, x, y;
	cin >> n >> x >> y;

	for(int i = 0; i < n+1; i++) {
		int x; cin >> x;
		a[x] = 1;
		b[N-1-x] = 1;
	}

	std::vector<int> v = multiply(a, b);

	for(int i = N; i < si(v); i++) {
		if(v[i])pre[i-N+1+y] = 1;
	}

	for(int i = 1; i < N*2; i++) {
		if(pre[i]) {
			for(int j = i; j < N*10; j += i)
				dp[j] = max(dp[j], i*2);
		}
	}
	int q; cin >> q;
	while(q--) {
		int l; cin >> l;
		l /= 2;
		cout << dp[l] << " ";
	}
}

signed main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    start = clock();

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif

    int test = 1;
    // cin >> test;

    cout << fixed << setprecision(2);

    for(int i = 1; i <= test; ++i){
    	solve();
    }

    cerr << time(start);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int sz=1<<19, mod=998244353;
int po(int x, int y)
{
    int re=1;
    while(y)
    {
        if(y&1) re=(1ll*re*x)%mod;
        y>>=1;
        x=(1ll*x*x)%mod;
    }
    return re;
}

const int w=po(3, (mod-1)/sz);
int A[sz], B[sz];

void ntt(int *A, int n, int w)
{
    int stw[n];
    stw[0]=1;
    for(int a=1; a<n; a++) stw[a]=(1ll*w*stw[a-1])%mod;
    for(int a=0, b=0; a<n; a++)
    {
        if(a<b) swap(A[a], A[b]);
        int i=(n>>1);
        while(b&i)
        {
            b-=i, i>>=1;
        }
        b+=i;
    }
    int cs=n;
    for(int i=1; i<n; i<<=1)
    {
        cs>>=1;
        for(int a=0; a<n; a+=(i<<1))
        {
            int st=0;
            for(int b=a; b<a+i; b++)
            {
                int x=A[b], y=(1ll*stw[st]*A[b+i])%mod;
                A[b]=x+y;
                if(A[b]>=mod) A[b]-=mod;
                A[b+i]=x-y;
                if(A[b+i]<0) A[b+i]+=mod;
                st+=cs;
            }
        }
    }
}

const int sz2=1e6+10;
int an[sz2];

int main()
{
    //freopen("input.txt", "r", stdin);
    int n, x, y;
    cin>>n>>x>>y;
    for(int a=0; a<=n; a++)
    {
        int p;
        scanf("%d", &p);
        A[p]=1, B[x-p]=1;
    }
    ntt(A, sz, w);
    ntt(B, sz, w);
    for(int a=0; a<sz; a++) A[a]=1ll*A[a]*B[a]%mod;
    ntt(A, sz, po(w, mod-2));
    for(int a=1; a<=x; a++)
    {
        if(A[a+x])
        {
            int l=(y+a)*2;
            for(int b=l; b<sz2; b+=l) an[b]=l;
        }
    }
    int q;
    cin>>q;
    for(int a=0; a<q; a++)
    {
        int l;
        scanf("%d", &l);
        if(an[l]) printf("%d ", an[l]);
        else printf("-1 ");
    }
}


//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define int long long
#define pb push_back
#define mod 1000000007
#define pll pair<long long,long long>
using namespace std;
long long power(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a)%mod;}
                a=(a*a)%mod;
                b>>=1;
        }
    return ans;

}
int find(int i,int a[]){
	if(a[i]==i)return i;
	return a[i]=find(a[i],a);
}
void uni(int i,int j,int a[],int sz[]){
	int x=find(i,a);
	int y=find(j,a);
	if(sz[x]>sz[y])a[y]=x;
	else a[x]=y;
	sz[x]+=sz[y];
	sz[y]=sz[x];
}
int ans[1000006];
bitset<200005>b1,b2;
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,x,y;
    cin>>n>>x>>y;
    n=n+1;
    int a[n];
    for(int i=0;i<n;i++){
    	cin>>a[i];
    }

    b1.reset();
    b2.reset();
    for(int i=1;i<n;i++){
    	b2.set(0,1);
    	b2<<=(a[i]-a[i-1]);
    	b1|=b2;
    }
    memset(ans,-1,sizeof(ans));
    for(int i=1;i<=x;i++){
        //cout<<b1[i]<<" ";
    	if(b1[i]){
    	    //cout<<i<<" ";
    		for(int j=(2*i+2*y);j<=1000000;j+=2*i+2*y){
    			ans[j]=2*i+2*y;
    		}
    	}
    }
    int q;
    cin>>q;
    while(q--){
    	int x1;
    	cin>>x1;
    	cout<<ans[x1]<<" ";
    }
    return 0;
}


//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define int long long
#define pb push_back
#define mod 1000000007
#define pll pair<long long,long long>
using namespace std;
long long power(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a)%mod;}
                a=(a*a)%mod;
                b>>=1;
        }
    return ans;

}
int find(int i,int a[]){
	if(a[i]==i)return i;
	return a[i]=find(a[i],a);
}
void uni(int i,int j,int a[],int sz[]){
	int x=find(i,a);
	int y=find(j,a);
	if(sz[x]>sz[y])a[y]=x;
	else a[x]=y;
	sz[x]+=sz[y];
	sz[y]=sz[x];
}
int ans[1000006];
bitset<200005>b1,b2;
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,x,y;
    cin>>n>>x>>y;
    n=n+1;
    int a[n];
    for(int i=0;i<n;i++){
    	cin>>a[i];
    }

    b1.reset();
    b2.reset();
    for(int i=1;i<n;i++){
    	b2.set(0,1);
    	b2<<=(a[i]-a[i-1]);
    	b1|=b2;
    }

    memset(ans,-1,sizeof(ans));
    for(int i=1;i<=x;i++){
        //cout<<b1[i]<<" ";
    	if(b1[i]){
    	    //cout<<i<<" ";
    		for(int j=(2*i+2*y);j<=1000000;j+=2*i+2*y){
    			ans[j]=2*i+2*y;
    		}
    	}
    }
    int q;
    cin>>q;
    while(q--){
    	int x1;
    	cin>>x1;
    	cout<<ans[x1]<<" ";
    }
    return 0;
}


// AVX-enabled std::bitset Pragmas (before #includes!)
// - bitset<200000> takes ~ 1ms per 1000 operations on GNU C++14 & GNU C++17
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2")  //Enable AVX

// =========== Template ========== //
#include <bits/stdc++.h>
using namespace std;
int fastio() { ios_base::sync_with_stdio(false); cout << fixed << setprecision(10); cin.tie(nullptr); return 0; }
int __fastio = fastio();
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p);
template<typename A> ostream& operator<<(ostream &os, const set<A> &m) { os << "{"; string sep = ""; for (auto e: m) os << sep << e, sep = ", "; return os << "}"; }
template<typename A> ostream& operator<<(ostream &os, const multiset<A> &m) { os << "{"; string sep = ""; for (auto e: m) os << sep << e, sep = ", "; return os << "}"; }
template<typename A, typename B> ostream& operator<<(ostream &os, const map<A, B> &m) { os << "{"; string sep = ""; for (auto e: m) os << sep << e.first << ": " << e.second, sep = ", "; return os << "}"; }
template<typename T>ostream& operator<<(ostream& os, const vector<T>& v) { os << "["; string sep = ""; for (auto e: v) os << sep << e, sep = ", "; return os << "]"; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#ifdef STEVEN
#define pp(...) cerr << "\t[" << #__VA_ARGS__ << "]:\t", dbg_out(__VA_ARGS__)
#define ppp(x) cerr << x << "\n"
#else
#define pp(...)
#define ppp(...)
#endif
template<class Fun> class y_combinator_result { Fun fun_; public: template<class T> explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {} template<class ...Args> decltype(auto) operator()(Args &&...args) { return fun_(std::ref(*this), std::forward<Args>(args)...); } };
template<class Fun> decltype(auto) y_combinator(Fun &&fun) { return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun)); }
#define yc y_combinator;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
#define fi first
#define se second
#define sz(x) (int((x).size()))
#define data _data
// =========== Book ============ //

using BS = bitset<1 << 18>;

#define setmax(a, b) a = max(a, b)
// ============= Solution ============= //
int main() {
   int T;
   // cin >> T;
   T = 1;
   for (int t = 1; t <= T; ++t) {
      int n, x, y;
      cin >> n >> x >> y;
      BS bs;
      vector<int> v(n + 1);
      for (int &i: v) cin >> i;
      for (int i: v) bs[i] = 1;
      int MAXN = 2E5 + 1;
      vector<bool> vis(MAXN);
      for (int i = 1; 2 * (i + y) < MAXN; ++i) {
         BS msk = bs & (bs << i);
         vis[2 * (i + y)] = msk.any();
      }
      vector<int> ans(MAXN, -1);
      for (int i = 1; i < MAXN; ++i) {
         if (!vis[i]) continue;
         for (int j = i; j < MAXN; j += i) {
            ans[j] = i;
         }
      }
      int q;
      cin >> q;
      for (int i = 0; i < q; ++i) {
         int len;
         cin >> len;
         cout << ans[len] << " ";
      }
      cout << "\n";
   }
}

// ============== Notes =============== //
// common bugs
// - fastio
// - int overflow (especially intermediate expressionns)
// - array bounds (indices bigger than MAXN?)
// - special cases (n=1? graph not connected?)
// - re-initialize efficiently between test cases


// AVX-enabled std::bitset Pragmas (before #includes!)
// - bitset<200000> takes ~ 1ms per 1000 operations on GNU C++14 & GNU C++17
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2")  //Enable AVX

// =========== Template ========== //
#include <bits/stdc++.h>
using namespace std;
int fastio() { ios_base::sync_with_stdio(false); cout << fixed << setprecision(10); cin.tie(nullptr); return 0; }
int __fastio = fastio();
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p);
template<typename A> ostream& operator<<(ostream &os, const set<A> &m) { os << "{"; string sep = ""; for (auto e: m) os << sep << e, sep = ", "; return os << "}"; }
template<typename A> ostream& operator<<(ostream &os, const multiset<A> &m) { os << "{"; string sep = ""; for (auto e: m) os << sep << e, sep = ", "; return os << "}"; }
template<typename A, typename B> ostream& operator<<(ostream &os, const map<A, B> &m) { os << "{"; string sep = ""; for (auto e: m) os << sep << e.first << ": " << e.second, sep = ", "; return os << "}"; }
template<typename T>ostream& operator<<(ostream& os, const vector<T>& v) { os << "["; string sep = ""; for (auto e: v) os << sep << e, sep = ", "; return os << "]"; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#ifdef STEVEN
#define pp(...) cerr << "\t[" << #__VA_ARGS__ << "]:\t", dbg_out(__VA_ARGS__)
#define ppp(x) cerr << x << "\n"
#else
#define pp(...)
#define ppp(...)
#endif
template<class Fun> class y_combinator_result { Fun fun_; public: template<class T> explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {} template<class ...Args> decltype(auto) operator()(Args &&...args) { return fun_(std::ref(*this), std::forward<Args>(args)...); } };
template<class Fun> decltype(auto) y_combinator(Fun &&fun) { return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun)); }
#define yc y_combinator;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
#define fi first
#define se second
#define sz(x) (int((x).size()))
#define data _data
// =========== Book ============ //

using BS = bitset<1 << 18>;

#define setmax(a, b) a = max(a, b)
// ============= Solution ============= //
int main() {
   int T;
   // cin >> T;
   T = 1;
   for (int t = 1; t <= T; ++t) {
      int n, x, y;
      cin >> n >> x >> y;
      BS bs;
      vector<int> v(n + 1);
      for (int &i: v) cin >> i;
      for (int i: v) bs[i] = 1;
      int MAXN = 1E6 + 1;
      vector<bool> vis(MAXN);
      for (int i = 1; i < (1 << 18) &&  2 * (i + y) < MAXN; ++i) {
         BS msk = bs & (bs << i);
         vis[2 * (i + y)] = msk.any();
      }
      vector<int> ans(MAXN, -1);
      for (int i = 1; i < MAXN; ++i) {
         if (!vis[i]) continue;
         for (int j = i; j < MAXN; j += i) {
            ans[j] = i;
         }
      }
      int q;
      cin >> q;
      for (int i = 0; i < q; ++i) {
         int len;
         cin >> len;
         cout << ans[len] << " ";
      }
      cout << "\n";
   }
}

// ============== Notes =============== //
// common bugs
// - fastio
// - int overflow (especially intermediate expressionns)
// - array bounds (indices bigger than MAXN?)
// - special cases (n=1? graph not connected?)
// - re-initialize efficiently between test cases


#include <bits/stdc++.h>
#define vec vector<int>
#define int64 long long int
#define cd std::complex<double>
#define clz(x) __builtin_clz(x)
const int maxN=(1<<20) , maxM=1e6+9 ;
const double PIE = acos(-1);
using namespace std;
cd p1[maxN],p2[maxN];
vec fact[maxN];
bool diff[maxN];
int si[maxN];
void fft(cd *coff,int n,int invert){

    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(coff[i], coff[j]);
    }

    for(int len=2;len<=n;len<<=1){
        double arg = 2 * PIE / len * invert ;
        cd wn(cos(arg),sin(arg));
        for(int i=0;i<n;i+=len){
            cd w(1);
            for(int j=0;2*j<len;j++){
                cd u = coff[i+j] , v = coff[i+j+(len>>1)] * w ;
                coff[i+j] = u + v , coff[i+j+(len>>1)] = u - v ;
                w *= wn ;
            }
        }
    }
    if(invert==-1)for(int i=0;i<n;i++)coff[i]/=n;
}
int solve(int L,int x,int y){
    int mx = 2*(x+y);
    if( L%2==1 || L>mx)return -1;
    int ret=-1;
    L/=2;
    for(int &d : fact[L]){
        if(y>=d)continue;
        if( diff[d-y] ) ret = 2 * d ;
    }
    return ret;
}
int main(){
    for(int i=1;i<maxN;i++){
        for(int j=i;j<maxN;j+=i){
            fact[j].push_back(i);
        }
    }
    int n , x , y ;
    scanf("%d%d%d",&n,&x,&y);
    for(int i=0;i<maxN;i++)p1[i]=p2[i]=cd(0,0);
    for(int i=0,a0;i<=n;i++){
        scanf("%d",&a0);
        p1[a0]=cd(1,0);
        p2[x-a0]=cd(1,0);
    }

    fft(p1,maxN,1);
    fft(p2,maxN,1);
    for(int i=0;i<maxN;i++)p1[i] *= p2[i];
    fft(p1,maxN,-1);
    for(int i=x;i<maxN;i++){
        int c0 = (int)(0.5 + p1[i].real());
        if(c0>0){
            diff[i-x]=1;
        }
    }

    int q , L ;
    scanf("%d",&q);
    while(q--){
        scanf("%d",&L);
        printf("%d ",solve(L,x,y));
    }
}


#include <bits/stdc++.h>
#define vec vector<int>
#define int64 long long int
#define cd std::complex<double>
#define clz(x) __builtin_clz(x)
const int maxN=(1<<20) , maxM=1e6+9 ;
const double PIE = acos(-1);
using namespace std;
cd p1[maxN],p2[maxN];
vec fact[maxN];
bool diff[maxN];
int si[maxN];
void fft(cd *coff,int n,int invert){

    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(coff[i], coff[j]);
    }

    for(int len=2;len<=n;len<<=1){
        double arg = 2 * PIE / len * invert ;
        cd wn(cos(arg),sin(arg));
        for(int i=0;i<n;i+=len){
            cd w(1);
            for(int j=0;2*j<len;j++){
                cd u = coff[i+j] , v = coff[i+j+(len>>1)] * w ;
                coff[i+j] = u + v , coff[i+j+(len>>1)] = u - v ;
                w *= wn ;
            }
        }
    }
    if(invert==-1)for(int i=0;i<n;i++)coff[i]/=n;
}
int solve(int L,int x,int y){
    int mx = 2*(x+y);
    int ret=-1;
    if(L%2==1)return false;
    L/=2;
    for(int &d : fact[L]){
        if(y>=d)continue;
        if( diff[d-y] ) ret = 2 * d ;
    }
    return ret;
}
int main(){
    for(int i=1;i<maxN;i++){
        for(int j=i;j<maxN;j+=i){
            fact[j].push_back(i);
        }
    }
    int n , x , y ;
    scanf("%d%d%d",&n,&x,&y);
    for(int i=0;i<maxN;i++)p1[i]=p2[i]=cd(0,0);
    for(int i=0,a0;i<=n;i++){
        scanf("%d",&a0);
        p1[a0]=cd(1,0);
        p2[x-a0]=cd(1,0);
    }

    fft(p1,maxN,1);
    fft(p2,maxN,1);
    for(int i=0;i<maxN;i++)p1[i] *= p2[i];
    fft(p1,maxN,-1);
    for(int i=x;i<maxN;i++){
        int c0 = (int)(0.5 + p1[i].real());
        if(c0>0){
            diff[i-x]=1;
        }
    }

    int q , L ;
    scanf("%d",&q);
    while(q--){
        scanf("%d",&L);
        printf("%d ",solve(L,x,y));
    }
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	int N , K;
	cin >> N >> K;
	string nombre;
	cin >> nombre;
	int indice = 0;
	for (int i = 0 ; i < K ; i++)
	{
		while (indice < N - 1 && !(nombre[indice] == '4' && nombre[indice + 1] == '7'))
		{
			indice++;
		}
		if (indice == N - 1)
		{
			break;
		}
		if (indice % 2 == 0)
		{
			nombre[indice + 1] = '4';
		}
		else
		{
			nombre[indice] = '7';
		}
		indice = max( 0 , indice - 1);

	}
	cout<<nombre<<endl;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	int N , K;
	cin >> N >> K;
	string nombre;
	cin >> nombre;
	int indice = 0;
	for (int i = 0 ; i < K ; i++)
	{
		while (indice < N - 1 && !(nombre[indice] == '4' && nombre[indice + 1] == '7'))
		{
			indice++;
		}
		if (indice == N - 1)
		{
			break;
		}
		if (indice < N - 2)
		{
			if (indice % 2 == 0)
			{
				if (nombre[indice + 2] == '7')
				{
					//cycle repere
					if ((K - i) % 2 == 1)
						nombre[indice + 1] = '4';
					break;
				}
			}
		}
		if (indice > 0)
		{
			if (indice % 2 == 1)
			{
				if (nombre[indice - 1] == '4')
				{
					if ((K - i) % 2 == 1)
						nombre[indice] = '7';
					break;
				}
			}
		}
		if (indice % 2 == 0)
		{
			nombre[indice + 1] = '4';
		}
		else
		{
			nombre[indice] = '7';
		}
		indice = max( 0 , indice - 1);

	}
	cout<<nombre<<endl;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	int N , K;
	cin >> N >> K;
	string nombre;
	cin >> nombre;
	int indice = 0;
	for (int i = 0 ; i < K ; i++)
	{
		while (indice < N - 1 && !(nombre[indice] == '4' && nombre[indice + 1] == '7'))
		{
			indice++;
		}
		if (indice == N - 1)
		{
			break;
		}
		if (indice < N - 2)
		{
			if (indice % 2 == 0)
			{
				if (nombre[indice + 2] == '7')
				{
					//cycle repere
					if ((K - i % 2) == 1)
						nombre[indice + 1] = '4';
					break;
				}
			}
		}
		if (indice > 0)
		{
			if (indice % 2 == 1)
			{
				if (nombre[indice - 1] == '4')
				{
					if ((K - i) % 2 == 1)
						nombre[indice] = '7';
					break;
				}
			}
		}
		if (indice % 2 == 0)
		{
			nombre[indice + 1] = '4';
		}
		else
		{
			nombre[indice] = '7';
		}
		indice = max( 0 , indice - 1);

	}
	cout<<nombre<<endl;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;

#define alpha ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define input(v,n) for(ll ppp=0; ppp<n; ppp++) cin>>v[ppp]
#define output(v,n) for(ll ppp=0; ppp<n; ppp++) cout<<v[ppp]<<" "
#define min3(a, b, c) min(a,min(b, c))
#define min4(a, b, c, d) min(a, min(b, min(c, d)))
#define max3(a, b, c) max(a,max(b, c))
#define max4(a, b, c, d) max(a, max(b, max(c, d)))
#define vi vector<ll>
#define vii vector<pair<ll, ll> >

const ld PI = acosl(-1.0);

//"Focus" on constraints.

int main()
{
	alpha

	string str;
	ll n,k;
	cin>>n>>k;
	cin>>str;
	ll pos=-1;
	set<ll> s;
	for(ll i=0; i<n-2; i++)
	{
		if((i+2)%2==0 && str[i]=='4' && str[i+1]=='4' && str[i+2]=='7')
		{
			pos=i+1;
			break;
		}
	}
	for(ll i=0; i<n-1; i++)
	{
		if(str[i]=='4' && str[i+1]=='7')
			s.insert(i);
	}
	for(auto it:s)
	{
		if(k==0) break;
		// cout<<it<<" "<<pos<<"\n";
		if(pos!=-1 && it==pos)
		{
			break;
		}
		else
		{
			if((it+1)%2==0) str[it]='7';
			else str[it+1]='4';
		}
		k--;
	}
	// cout<<k<<" "<<str<<"\n";
	if(k==0)
	{
		cout<<str;
		return 0;
	}
	if(pos==-1 && k!=0)
	{
		cout<<str;
		return 0;
	}
	k%=2;
	if(k==1) str[pos]='7';
	cout<<str;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;

#define alpha ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define input(v,n) for(ll ppp=0; ppp<n; ppp++) cin>>v[ppp]
#define output(v,n) for(ll ppp=0; ppp<n; ppp++) cout<<v[ppp]<<" "
#define min3(a, b, c) min(a,min(b, c))
#define min4(a, b, c, d) min(a, min(b, min(c, d)))
#define max3(a, b, c) max(a,max(b, c))
#define max4(a, b, c, d) max(a, max(b, max(c, d)))
#define vi vector<ll>
#define vii vector<pair<ll, ll> >

const ld PI = acosl(-1.0);

//"Focus" on constraints.

int main()
{
	alpha

	string str;
	ll n,k;
	cin>>n>>k;
	cin>>str;
	ll pos=-1;
	set<ll> s;
	for(ll i=0; i<n-2; i++)
	{
		if((i+2)%2==0 && str[i]=='4' && str[i+1]=='4' && str[i+2]=='7')
		{
			pos=i+1;
			break;
		}
	}
	for(ll i=0; i<n-1; i++)
	{
		if(str[i]=='4' && str[i+1]=='7')
			s.insert(i);
	}
	for(auto it:s)
	{
		if(k==0) break;
		// cout<<it<<" "<<pos<<"\n";
		if(pos!=-1 && it==pos)
		{
			break;
		}
		else
		{
			if((it+1)%2==0) str[it]='7';
			else
			{
				// cout<<"HI";
				str[it+1]='4';
				if(it+2<n && str[it]=='4' && str[it+2]=='7')
				{
					pos=it+1;
					k--;
					break;
				}
				// if((it+2)%2==0 && s.find(it+1)!=s.end())
				// 	pos=it+2;
			}
		}
		// cout<<str<<"\n";
		k--;
	}
	// cout<<k<<" "<<str<<" "<<pos<<"\n";
	if(k==0)
	{
		cout<<str;
		return 0;
	}
	if(pos==-1 && k!=0)
	{
		cout<<str;
		return 0;
	}
	k%=2;
	if(k==1) {
		if(str[pos]=='7')
			str[pos]='4';
		else
			str[pos]='7';
	}
	cout<<str;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;

#define alpha ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define input(v,n) for(ll ppp=0; ppp<n; ppp++) cin>>v[ppp]
#define output(v,n) for(ll ppp=0; ppp<n; ppp++) cout<<v[ppp]<<" "
#define min3(a, b, c) min(a,min(b, c))
#define min4(a, b, c, d) min(a, min(b, min(c, d)))
#define max3(a, b, c) max(a,max(b, c))
#define max4(a, b, c, d) max(a, max(b, max(c, d)))
#define vi vector<ll>
#define vii vector<pair<ll, ll> >

const ld PI = acosl(-1.0);

//"Focus" on constraints.

int main()
{
	alpha

	string str;
	ll n,k;
	cin>>n>>k;
	cin>>str;
	ll pos=-1;
	set<ll> s;
	for(ll i=0; i<n-2; i++)
	{
		if((i+2)%2==0 && str[i]=='4' && str[i+1]=='4' && str[i+2]=='7')
		{
			pos=i+1;
			break;
		}
	}
	for(ll i=0; i<n-1; i++)
	{
		if(str[i]=='4' && str[i+1]=='7')
			s.insert(i);
	}
	for(auto it:s)
	{
		if(k==0) break;
		// cout<<it<<" "<<pos<<"\n";
		if(pos!=-1 && it==pos)
		{
			break;
		}
		else
		{
			if((it+1)%2==0) str[it]='7';
			else
			{
				str[it+1]='4';
				if(it+2<n && str[it]=='4' && str[it+2]=='7')
					pos=it+1;
				// if((it+2)%2==0 && s.find(it+1)!=s.end())
				// 	pos=it+2;
			}
		}
		// cout<<str<<"\n";
		k--;
	}
	// cout<<k<<" "<<str<<" "<<pos<<"\n";
	if(k==0)
	{
		cout<<str;
		return 0;
	}
	if(pos==-1 && k!=0)
	{
		cout<<str;
		return 0;
	}
	k%=2;
	if(k==1) {
		if(str[pos]=='7')
			str[pos]='4';
		else
			str[pos]='7';
	}
	cout<<str;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;
void luckyTransformation(string &str, int ops){
    int index = 0;
    int i = 0;
    while(ops--){
        index = str.find_first_of('4', i);
        if(index == -1)
            return;
        if( str[index+1] != '7' ){
            i = index+1;
            continue;
        }
        if(index%2 == 0) //even
            str[index] = '4', str[index+1] = '4';
        else //odd
            str[index] = '7', str[index+1] = '7';
        i = index+2;
    }
    return;
}
int main(){
    string number;
    int size, ops;
    cin>> size>> ops;
    cin>>number;

    luckyTransformation(number, ops);

    cout<<number<<endl;
}


#include<bits/stdc++.h>

using namespace std;
int size = 3;
void luckyTransformation(string &str, int ops){
    int index=0;
    while( ops && index<str.size()){
         if( !str.compare(index, 3, "447") && (index%2) == 0 )
            ops%=2;
         if( ops && !str.compare(index, 2, "47")){
            str[index] = (index%2)?'7':'4';
            str[index+1] = str[index];
            index-=2;
            ops--;
         }
         if(index < 0)
            index=0;
         else index++;
    }

    return;
}
int main(){
    string number;
    int ops;
    cin>> size>> ops;
    cin>>number;
    luckyTransformation(number, ops);

    cout<<number<<endl;
}


#include<bits/stdc++.h>

using namespace std;
void luckyTransformation(string &str, int ops){
    int index = 0;
    int i = 0;
    while(ops--){
        index = str.find_first_of('4', i);
        if(index == -1)
            return;
        if( str[index+1] != '7' ){
            i = index+1;
            continue;
        }
        if(index%2 == 0) //even
            str[index] = '4', str[index+1] = '4';
        else //odd
            str[index] = '7', str[index+1] = '7';
        i = index+2;
    }
    return;
}
int main(){
    string number;
    int size, ops;
    cin>> size>> ops;
    cin>>number;

    luckyTransformation(number, ops);

    cout<<number;
}


#include<bits/stdc++.h>

using namespace std;
void luckyTransformation(string &str, int ops){
    int index = 0;
    int i = 0;
    while(ops--){
        index = str.find_first_of('4');
        if(index == -1)
            return;
        if( str[index+1] != '7' ){
            continue;
        }
        if(index%2 == 0) //even
            str[index] = '4', str[index+1] = '4';
        else //odd
            str[index] = '7', str[index+1] = '7';
    }
    return;
}
int main(){
    string number;
    int size, ops;
    cin>> size>> ops;
    cin>>number;

    luckyTransformation(number, ops);

    cout<<number;
}


#include<bits/stdc++.h>

using namespace std;
void luckyTransformation(string &str, int ops){
    int index = 0;
    int i = 0;
    while(ops){
        index = str.find_first_of('4', i);
        if(index == -1)
            return;
        if( str[index+1] != '7' ){
            i = index+1;
            continue;
        }
        if(index%2 == 0) //even
            str[index] = '4', str[index+1] = '4';
        else //odd
            str[index] = '7', str[index+1] = '7';
        i = 0;
        ops--;
    }
    return;
}
int main(){
    string number;
    int size, ops;
    cin>> size>> ops;
    cin>>number;

    luckyTransformation(number, ops);

    cout<<number;
}


#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define yala_bena cin.tie(0); std::ios::sync_with_stdio(false);
#define Open freopen(".txt" , "r", stdin); freopen(".txt" , "w" , stdout);
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
int main()
{
    yala_bena
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    for(int i=0;i<n-1;i++)
    {
      if(s[i]=='4' && s[i+1]=='7' && k)
      {
          if((i+1)%2)
          {
            s[i]=s[i+1]='4';
          }
          else
          {
            s[i]=s[i+1]='7';
            if(i-1>=0 && s[i-1]=='4')
                i-=2;
          }
          k--;
      }
    }
    cout<<s<<endl;
}


#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define yala_bena cin.tie(0); std::ios::sync_with_stdio(false);
#define Open freopen(".txt" , "r", stdin); freopen(".txt" , "w" , stdout);
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
int main()
{
    yala_bena
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    unordered_map<string,bool> taken;
    unordered_map<string,int> pos;
    vector<string > v;
    taken[s]=1;
    pos[s]=v.size();
    v.pb(s);

    for(int i=0;i<n-1 && k;i++)
    {
      if(s[i]=='4' && s[i+1]=='7' && k)
      {
          if((i+1)%2)
          {
            s[i]=s[i+1]='4';
          }
          else if(i-1>=0 && s[i-1]=='4')
          {
              if(k%2)
                s[i]='7';
              else
                s[i]='4';
              break;
          }
          else
          {
            s[i]=s[i+1]='7';
          }
          k--;

      }
    }
    cout<<s<<endl;
}