// #pragma GCC optimize ("O3")
#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;

template<class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update> ;

template<class key, class value, class cmp = std::less<key>>
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;

struct custom_hash { // Credits: https://codeforces.com/blog/entry/62393
	static uint64_t splitmix64(uint64_t x) {
		// http://xorshift.di.unimi.it/splitmix64.c
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}

	size_t operator()(uint64_t x) const {
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
	size_t operator()(pair<int64_t, int64_t> Y) const {
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(Y.first * 31 + Y.second + FIXED_RANDOM);
	}
};

template<class T> ostream& operator<<(ostream &os, vector<T> V) {
	os << "[ ";
	for (auto v : V) os << v << " ";
	return os << "]";
}
template<class T> ostream& operator<<(ostream &os, set<T> S) {
	os << "{ ";
	for (auto s : S) os << s << " ";
	return os << "}";
}
template<class T> ostream& operator<<(ostream &os, unordered_set<T> S) {
	os << "{ ";
	for (auto s : S) os << s << " ";
	return os << "}";
}
template<class T> ostream& operator << (ostream& os, multiset<T> S) {
	os << "{ ";
	for (auto s : S) os << s << " ";
	return os << "}";
}
template<class T> ostream& operator<<(ostream &os, ordered_set<T> S) {
	os << "{ ";
	for (auto s : S) os << s << " ";
	return os << "}";
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L, R> P) {
	return os << "(" << P.first << "," << P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L, R> M) {
	os << "{ ";
	for (auto m : M) os << "(" << m.first << ":" << m.second << ") ";
	return os << "}";
}
template<class L, class R, class chash = std::hash<R>> ostream & operator<<(ostream &os, unordered_map<L, R, chash> M) {
	os << "{ ";
	for (auto m : M) os << "(" << m.first << ":" << m.second << ") ";
	return os << "}";
}
template<class L, class R, class chash = std::hash<R> > ostream & operator<<(ostream &os, gp_hash_table<L, R, chash> M) {
	os << "{ ";
	for (auto m : M) os << "(" << m.first << ":" << m.second << ") ";
	return os << "}";
}

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

inline int64_t random_long(long long l, long long r) {
	uniform_int_distribution<int64_t> generator(l, r);
	return generator(rng);
}
inline int64_t random_long() {
	uniform_int_distribution<int64_t> generator(LLONG_MIN, LLONG_MAX);
	return generator(rng);

}

/////-----------------------------\\\\\

#define ll long long
#define ld long double
#define all(v) v.begin(),v.end()
#define pb push_back
#define S second
#define F first
#define die() return 0;

#define md          998244853
#define fmd         998244353
#define M           5000
#define M1          40000100
#define M2          300
#define MM          100000000000
#define N           10
#define i32 int32_t

#define RBTTYPE int
#define ordered_set tree<RBTTYPE, null_type, less<RBTTYPE>, rb_tree_tag,tree_order_statistics_node_update>

// typedef __int128_t ull;
typedef unsigned long long ULL;
const long long Inf = 1e18;
const long long INF64 = 3e18;

ll exp(ll a, ll b) {ll r = 1; while (b) {if (b & 1)r = r * a % md, r %= md; a = (a * a % md) % md; b /= 2;} return r % md;}
ll exp(ll a, ll b, ll m) {ll r = 1; while (b) {if (b & 1)r = r * a % m, r %= m; a = (a * a % m) % m; b /= 2;} return r % m;}
ll gcd(ll a, ll b) {if (a < b)swap(a, b); if (b == 0)return a; return gcd(b, a % b);}
template<typename T>T pw(T a, ll b) {T ans{1}; while (b) {while (!(b & 1)) b >>= 1, a = (a * a); ans = (ans * a), --b;} return ans;}

using ht = gp_hash_table<ll, ll, custom_hash> ;
/////-----------------------------\\\\\

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

void fft(vector<cd> &a, bool iv = 0) {
	int n = a.size();
	for (int i = 1, j = 0; i < n; ++i) {
		int b = n >> 1;
		for (; j & b; b >>= 1)
			j ^= b;
		j ^= b;
		if (i < j)swap(a[i], a[j]);
	}
	for (int l = 2; l <= n; l *= 2) {
		double ang = 2 * PI / l * (iv ? -1 : 1);
		cd wlen(cos(ang), sin(ang));
		for (int i = 0; i < n; i += l) {
			cd w(1);
			for (int j = 0; j < l / 2; j++) {
				cd u = a[i + j], v = a[i + j + l / 2] * w;
				a[i + j] = u + v;
				a[i + j + l / 2] = u - v;
				w *= wlen;
			}
		}
	}
	if (iv) {
		for (auto &p : a)p /= n;
	}
}
vector<int> fftMul(vector<int> a,vector<int> b){
	vector<cd> fa(all(a)),fb(all(b));
	int n=1;
	while(n<a.size()+b.size()){
		n*=2;
	}
	fa.resize(n);fb.resize(n);
	fft(fa);
	fft(fb);

	for(int i=0;i<n;++i){
		fa[i]*=fb[i];
	}
	fft(fa,1);

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

int solve() {
	ll n, i, j, k, m, x, y, z;
	cin >> n >> x >> y;
	int ma=2e5+10000;
	m=2e5+100;
	vector<int> a(m);
	vector<int> b(ma+10);
	for(i=0;i<=n;++i){
		cin>>x;
		a[x]=1;
		b[ma-x]=1;
	}
	vector<int> c=fftMul(a,b);
	vector<int> del(5e5+1);
	for(i=ma+1;i<c.size();++i){
		if(!c[i])continue;
		if(y+i-ma<del.size()){
			del[y+i-ma]=1;
		}
	}

	// trace(c);
	vector<int> ans(5e5,-1);
	for(int i=2;i<=5e5;++i){
		for(j=i;j<=5e5;j+=i){
			if(!del[i])continue;
			ans[j]=max(ans[j],i);
		}
	}

	int t;
	cin>>t;
	while(t--){
		cin>>x;
		// trace(x);
		x/=2;
		ll p=ans[x];
		if(p<0){
			cout<<"-1 ";
		}
		else{
			cout<<2*p<<" ";
		}
	}cout<<"\n";

	die();
}

void prec() {

}

// #define FILE_INPUT

int main() {

#ifndef ONLINE_JUDGE
	double _tBeg = clock();
#endif
	// Use "set_name".max_load_factor(0.25);"set_name".reserve(512); with unordered set
	// unordered_map<long long, ll, custom_hash> safe_map;
	// gp_hash_table<long long, ll, custom_hash> safe_hash_table;

	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#ifdef FILE_INPUT
	char *inputFile = "input.txt";
	char *outputFile = "fibs.txt";
	freopen(inputFile, "r", stdin);
	freopen(outputFile, "w", stdout);
#endif

	int t;
	t = 1;;
	prec();
	// cin >> t;

	int _case = 1;
	while (t--) {
		// cout<<"Case #"<<_case++<<": ";
		solve();
	}

#ifndef ONLINE_JUDGE
	double _tEnd = clock();
	// printf("\ntotal time %.6f\n",(_tEnd-_tBeg)/CLOCKS_PER_SEC);
#endif

	die();
}


// #pragma GCC optimize ("O3")
#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;

template<class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update> ;

template<class key, class value, class cmp = std::less<key>>
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;

struct custom_hash { // Credits: https://codeforces.com/blog/entry/62393
	static uint64_t splitmix64(uint64_t x) {
		// http://xorshift.di.unimi.it/splitmix64.c
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}

	size_t operator()(uint64_t x) const {
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
	size_t operator()(pair<int64_t, int64_t> Y) const {
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(Y.first * 31 + Y.second + FIXED_RANDOM);
	}
};

template<class T> ostream& operator<<(ostream &os, vector<T> V) {
	os << "[ ";
	for (auto v : V) os << v << " ";
	return os << "]";
}
template<class T> ostream& operator<<(ostream &os, set<T> S) {
	os << "{ ";
	for (auto s : S) os << s << " ";
	return os << "}";
}
template<class T> ostream& operator<<(ostream &os, unordered_set<T> S) {
	os << "{ ";
	for (auto s : S) os << s << " ";
	return os << "}";
}
template<class T> ostream& operator << (ostream& os, multiset<T> S) {
	os << "{ ";
	for (auto s : S) os << s << " ";
	return os << "}";
}
template<class T> ostream& operator<<(ostream &os, ordered_set<T> S) {
	os << "{ ";
	for (auto s : S) os << s << " ";
	return os << "}";
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L, R> P) {
	return os << "(" << P.first << "," << P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L, R> M) {
	os << "{ ";
	for (auto m : M) os << "(" << m.first << ":" << m.second << ") ";
	return os << "}";
}
template<class L, class R, class chash = std::hash<R>> ostream & operator<<(ostream &os, unordered_map<L, R, chash> M) {
	os << "{ ";
	for (auto m : M) os << "(" << m.first << ":" << m.second << ") ";
	return os << "}";
}
template<class L, class R, class chash = std::hash<R> > ostream & operator<<(ostream &os, gp_hash_table<L, R, chash> M) {
	os << "{ ";
	for (auto m : M) os << "(" << m.first << ":" << m.second << ") ";
	return os << "}";
}

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

inline int64_t random_long(long long l, long long r) {
	uniform_int_distribution<int64_t> generator(l, r);
	return generator(rng);
}
inline int64_t random_long() {
	uniform_int_distribution<int64_t> generator(LLONG_MIN, LLONG_MAX);
	return generator(rng);

}

/////-----------------------------\\\\\

#define ll long long
#define ld long double
#define all(v) v.begin(),v.end()
#define pb push_back
#define S second
#define F first
#define die() return 0;

#define md          998244853
#define fmd         998244353
#define M           5000
#define M1          40000100
#define M2          300
#define MM          100000000000
#define N           10
#define i32 int32_t

#define RBTTYPE int
#define ordered_set tree<RBTTYPE, null_type, less<RBTTYPE>, rb_tree_tag,tree_order_statistics_node_update>

// typedef __int128_t ull;
typedef unsigned long long ULL;
const long long Inf = 1e18;
const long long INF64 = 3e18;

ll exp(ll a, ll b) {ll r = 1; while (b) {if (b & 1)r = r * a % md, r %= md; a = (a * a % md) % md; b /= 2;} return r % md;}
ll exp(ll a, ll b, ll m) {ll r = 1; while (b) {if (b & 1)r = r * a % m, r %= m; a = (a * a % m) % m; b /= 2;} return r % m;}
ll gcd(ll a, ll b) {if (a < b)swap(a, b); if (b == 0)return a; return gcd(b, a % b);}
template<typename T>T pw(T a, ll b) {T ans{1}; while (b) {while (!(b & 1)) b >>= 1, a = (a * a); ans = (ans * a), --b;} return ans;}

using ht = gp_hash_table<ll, ll, custom_hash> ;
/////-----------------------------\\\\\

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

void fft(vector<cd> &a, bool iv = 0) {
	int n = a.size();
	for (int i = 1, j = 0; i < n; ++i) {
		int b = n >> 1;
		for (; j & b; b >>= 1)
			j ^= b;
		j ^= b;
		if (i < j)swap(a[i], a[j]);
	}
	for (int l = 2; l <= n; l *= 2) {
		double ang = 2 * PI / l * (iv ? -1 : 1);
		cd wlen(cos(ang), sin(ang));
		for (int i = 0; i < n; i += l) {
			cd w(1);
			for (int j = 0; j < l / 2; j++) {
				cd u = a[i + j], v = a[i + j + l / 2] * w;
				a[i + j] = u + v;
				a[i + j + l / 2] = u - v;
				w *= wlen;
			}
		}
	}
	if (iv) {
		for (auto &p : a)p /= n;
	}
}
vector<int> fftMul(vector<int> a,vector<int> b){
	vector<cd> fa(all(a)),fb(all(b));
	int n=1;
	while(n<a.size()+b.size()){
		n*=2;
	}
	fa.resize(n);fb.resize(n);
	fft(fa);
	fft(fb);

	for(int i=0;i<n;++i){
		fa[i]*=fb[i];
	}
	fft(fa,1);

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

int solve() {
	ll n, i, j, k, m, x, y, z;
	cin >> n >> x >> y;
	int ma=2e5+10000;
	m=2e5+100;
	vector<int> a(m);
	vector<int> b(ma+10);
	for(i=0;i<=n;++i){
		cin>>x;
		a[x]=1;
		b[ma-x]=1;
	}
	vector<int> c=fftMul(a,b);
	vector<int> del(m);
	for(i=ma+1;i<c.size();++i){
		if(!c[i])continue;
		if(y+i-ma<m){
			del[y+i-ma]=1;
		}
	}

	// trace(c);
	vector<int> ans(5e5,-1);
	for(int i=2;i<=5e5;++i){
		for(j=i;j<=5e5;j+=i){
			if(!del[i])continue;
			ans[j]=max(ans[j],i);
		}
	}

	int t;
	cin>>t;
	while(t--){
		cin>>x;
		// trace(x);
		x/=2;
		ll p=ans[x];
		if(p<0){
			cout<<"-1 ";
		}
		else{
			cout<<2*p<<" ";
		}
	}cout<<"\n";

	die();
}

void prec() {

}

// #define FILE_INPUT

int main() {

#ifndef ONLINE_JUDGE
	double _tBeg = clock();
#endif
	// Use "set_name".max_load_factor(0.25);"set_name".reserve(512); with unordered set
	// unordered_map<long long, ll, custom_hash> safe_map;
	// gp_hash_table<long long, ll, custom_hash> safe_hash_table;

	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#ifdef FILE_INPUT
	char *inputFile = "input.txt";
	char *outputFile = "fibs.txt";
	freopen(inputFile, "r", stdin);
	freopen(outputFile, "w", stdout);
#endif

	int t;
	t = 1;;
	prec();
	// cin >> t;

	int _case = 1;
	while (t--) {
		// cout<<"Case #"<<_case++<<": ";
		solve();
	}

#ifndef ONLINE_JUDGE
	double _tEnd = clock();
	// printf("\ntotal time %.6f\n",(_tEnd-_tBeg)/CLOCKS_PER_SEC);
#endif

	die();
}


// #pragma GCC optimize ("O3")
#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;

template<class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update> ;

template<class key, class value, class cmp = std::less<key>>
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;

struct custom_hash { // Credits: https://codeforces.com/blog/entry/62393
	static uint64_t splitmix64(uint64_t x) {
		// http://xorshift.di.unimi.it/splitmix64.c
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}

	size_t operator()(uint64_t x) const {
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
	size_t operator()(pair<int64_t, int64_t> Y) const {
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(Y.first * 31 + Y.second + FIXED_RANDOM);
	}
};

template<class T> ostream& operator<<(ostream &os, vector<T> V) {
	os << "[ ";
	for (auto v : V) os << v << " ";
	return os << "]";
}
template<class T> ostream& operator<<(ostream &os, set<T> S) {
	os << "{ ";
	for (auto s : S) os << s << " ";
	return os << "}";
}
template<class T> ostream& operator<<(ostream &os, unordered_set<T> S) {
	os << "{ ";
	for (auto s : S) os << s << " ";
	return os << "}";
}
template<class T> ostream& operator << (ostream& os, multiset<T> S) {
	os << "{ ";
	for (auto s : S) os << s << " ";
	return os << "}";
}
template<class T> ostream& operator<<(ostream &os, ordered_set<T> S) {
	os << "{ ";
	for (auto s : S) os << s << " ";
	return os << "}";
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L, R> P) {
	return os << "(" << P.first << "," << P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L, R> M) {
	os << "{ ";
	for (auto m : M) os << "(" << m.first << ":" << m.second << ") ";
	return os << "}";
}
template<class L, class R, class chash = std::hash<R>> ostream & operator<<(ostream &os, unordered_map<L, R, chash> M) {
	os << "{ ";
	for (auto m : M) os << "(" << m.first << ":" << m.second << ") ";
	return os << "}";
}
template<class L, class R, class chash = std::hash<R> > ostream & operator<<(ostream &os, gp_hash_table<L, R, chash> M) {
	os << "{ ";
	for (auto m : M) os << "(" << m.first << ":" << m.second << ") ";
	return os << "}";
}

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

inline int64_t random_long(long long l, long long r) {
	uniform_int_distribution<int64_t> generator(l, r);
	return generator(rng);
}
inline int64_t random_long() {
	uniform_int_distribution<int64_t> generator(LLONG_MIN, LLONG_MAX);
	return generator(rng);

}

/////-----------------------------\\\\\

#define ll long long
#define ld long double
#define all(v) v.begin(),v.end()
#define pb push_back
#define S second
#define F first
#define die() return 0;

#define md          998244853
#define fmd         998244353
#define M           5000
#define M1          40000100
#define M2          300
#define MM          100000000000
#define N           10
#define i32 int32_t

#define RBTTYPE int
#define ordered_set tree<RBTTYPE, null_type, less<RBTTYPE>, rb_tree_tag,tree_order_statistics_node_update>

// typedef __int128_t ull;
typedef unsigned long long ULL;
const long long Inf = 1e18;
const long long INF64 = 3e18;

ll exp(ll a, ll b) {ll r = 1; while (b) {if (b & 1)r = r * a % md, r %= md; a = (a * a % md) % md; b /= 2;} return r % md;}
ll exp(ll a, ll b, ll m) {ll r = 1; while (b) {if (b & 1)r = r * a % m, r %= m; a = (a * a % m) % m; b /= 2;} return r % m;}
ll gcd(ll a, ll b) {if (a < b)swap(a, b); if (b == 0)return a; return gcd(b, a % b);}
template<typename T>T pw(T a, ll b) {T ans{1}; while (b) {while (!(b & 1)) b >>= 1, a = (a * a); ans = (ans * a), --b;} return ans;}

using ht = gp_hash_table<ll, ll, custom_hash> ;
/////-----------------------------\\\\\

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

void fft(vector<cd> &a, bool iv = 0) {
	int n = a.size();
	for (int i = 1, j = 0; i < n; ++i) {
		int b = n >> 1;
		for (; j & b; b >>= 1)
			j ^= b;
		j ^= b;
		if (i < j)swap(a[i], a[j]);
	}
	for (int l = 2; l <= n; l *= 2) {
		double ang = 2 * PI / l * (iv ? -1 : 1);
		cd wlen(cos(ang), sin(ang));
		for (int i = 0; i < n; i += l) {
			cd w(1);
			for (int j = 0; j < l / 2; j++) {
				cd u = a[i + j], v = a[i + j + l / 2] * w;
				a[i + j] = u + v;
				a[i + j + l / 2] = u - v;
				w *= wlen;
			}
		}
	}
	if (iv) {
		for (auto &p : a)p /= n;
	}
}
vector<int> fftMul(vector<int> a,vector<int> b){
	vector<cd> fa(all(a)),fb(all(b));
	int n=1;
	while(n<a.size()+b.size()){
		n*=2;
	}
	fa.resize(n);fb.resize(n);
	fft(fa);
	fft(fb);

	for(int i=0;i<n;++i){
		fa[i]*=fb[i];
	}
	fft(fa,1);

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

int solve() {
	ll n, i, j, k, m, x, y, z;
	cin >> n >> x >> y;
	int ma=2e5+10000;
	m=2e5+100;
	vector<int> a(m);
	vector<int> b(ma+10);
	for(i=0;i<=n;++i){
		cin>>x;
		a[x]=1;
		b[ma-x]=1;
	}
	int l=5e5+100;
	vector<int> c=fftMul(a,b);
	vector<int> del(l);
	for(i=ma+1;i<c.size();++i){
		if(!c[i])continue;
		if(y+i-ma<l){
			del[y+i-ma]=1;
		}
	}

	// trace(c);
	vector<int> ans(l,-1);
	for(int i=2;i<l;++i){
		for(j=i;j<l;j+=i){
			if(!del[i])continue;
			ans[j]=max(ans[j],i);
		}
	}

	int t;
	cin>>t;
	while(t--){
		cin>>x;
		// trace(x);
		x/=2;
		ll p=ans[x];
		if(p<0){
			cout<<"-1 ";
		}
		else{
			cout<<2*p<<" ";
		}
	}cout<<"\n";

	die();
}

void prec() {

}

// #define FILE_INPUT

int main() {

#ifndef ONLINE_JUDGE
	double _tBeg = clock();
#endif
	// Use "set_name".max_load_factor(0.25);"set_name".reserve(512); with unordered set
	// unordered_map<long long, ll, custom_hash> safe_map;
	// gp_hash_table<long long, ll, custom_hash> safe_hash_table;

	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#ifdef FILE_INPUT
	char *inputFile = "input.txt";
	char *outputFile = "fibs.txt";
	freopen(inputFile, "r", stdin);
	freopen(outputFile, "w", stdout);
#endif

	int t;
	t = 1;;
	prec();
	// cin >> t;

	int _case = 1;
	while (t--) {
		// cout<<"Case #"<<_case++<<": ";
		solve();
	}

#ifndef ONLINE_JUDGE
	double _tEnd = clock();
	// printf("\ntotal time %.6f\n",(_tEnd-_tBeg)/CLOCKS_PER_SEC);
#endif

	die();
}


// #pragma GCC optimize ("O3")
#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;

template<class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update> ;

template<class key, class value, class cmp = std::less<key>>
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;

struct custom_hash { // Credits: https://codeforces.com/blog/entry/62393
	static uint64_t splitmix64(uint64_t x) {
		// http://xorshift.di.unimi.it/splitmix64.c
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}

	size_t operator()(uint64_t x) const {
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
	size_t operator()(pair<int64_t, int64_t> Y) const {
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(Y.first * 31 + Y.second + FIXED_RANDOM);
	}
};

template<class T> ostream& operator<<(ostream &os, vector<T> V) {
	os << "[ ";
	for (auto v : V) os << v << " ";
	return os << "]";
}
template<class T> ostream& operator<<(ostream &os, set<T> S) {
	os << "{ ";
	for (auto s : S) os << s << " ";
	return os << "}";
}
template<class T> ostream& operator<<(ostream &os, unordered_set<T> S) {
	os << "{ ";
	for (auto s : S) os << s << " ";
	return os << "}";
}
template<class T> ostream& operator << (ostream& os, multiset<T> S) {
	os << "{ ";
	for (auto s : S) os << s << " ";
	return os << "}";
}
template<class T> ostream& operator<<(ostream &os, ordered_set<T> S) {
	os << "{ ";
	for (auto s : S) os << s << " ";
	return os << "}";
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L, R> P) {
	return os << "(" << P.first << "," << P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L, R> M) {
	os << "{ ";
	for (auto m : M) os << "(" << m.first << ":" << m.second << ") ";
	return os << "}";
}
template<class L, class R, class chash = std::hash<R>> ostream & operator<<(ostream &os, unordered_map<L, R, chash> M) {
	os << "{ ";
	for (auto m : M) os << "(" << m.first << ":" << m.second << ") ";
	return os << "}";
}
template<class L, class R, class chash = std::hash<R> > ostream & operator<<(ostream &os, gp_hash_table<L, R, chash> M) {
	os << "{ ";
	for (auto m : M) os << "(" << m.first << ":" << m.second << ") ";
	return os << "}";
}

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

inline int64_t random_long(long long l, long long r) {
	uniform_int_distribution<int64_t> generator(l, r);
	return generator(rng);
}
inline int64_t random_long() {
	uniform_int_distribution<int64_t> generator(LLONG_MIN, LLONG_MAX);
	return generator(rng);

}

/////-----------------------------\\\\\

#define ll long long
#define ld long double
#define all(v) v.begin(),v.end()
#define pb push_back
#define S second
#define F first
#define die() return 0;

#define md          998244853
#define fmd         998244353
#define M           5000
#define M1          40000100
#define M2          300
#define MM          100000000000
#define N           10
#define i32 int32_t

#define RBTTYPE int
#define ordered_set tree<RBTTYPE, null_type, less<RBTTYPE>, rb_tree_tag,tree_order_statistics_node_update>

// typedef __int128_t ull;
typedef unsigned long long ULL;
const long long Inf = 1e18;
const long long INF64 = 3e18;

ll exp(ll a, ll b) {ll r = 1; while (b) {if (b & 1)r = r * a % md, r %= md; a = (a * a % md) % md; b /= 2;} return r % md;}
ll exp(ll a, ll b, ll m) {ll r = 1; while (b) {if (b & 1)r = r * a % m, r %= m; a = (a * a % m) % m; b /= 2;} return r % m;}
ll gcd(ll a, ll b) {if (a < b)swap(a, b); if (b == 0)return a; return gcd(b, a % b);}
template<typename T>T pw(T a, ll b) {T ans{1}; while (b) {while (!(b & 1)) b >>= 1, a = (a * a); ans = (ans * a), --b;} return ans;}

using ht = gp_hash_table<ll, ll, custom_hash> ;
/////-----------------------------\\\\\

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

void fft(vector<cd> &a, bool iv = 0) {
	int n = a.size();
	for (int i = 1, j = 0; i < n; ++i) {
		int b = n >> 1;
		for (; j & b; b >>= 1)
			j ^= b;
		j ^= b;
		if (i < j)swap(a[i], a[j]);
	}
	for (int l = 2; l <= n; l *= 2) {
		double ang = 2 * PI / l * (iv ? -1 : 1);
		cd wlen(cos(ang), sin(ang));
		for (int i = 0; i < n; i += l) {
			cd w(1);
			for (int j = 0; j < l / 2; j++) {
				cd u = a[i + j], v = a[i + j + l / 2] * w;
				a[i + j] = u + v;
				a[i + j + l / 2] = u - v;
				w *= wlen;
			}
		}
	}
	if (iv) {
		for (auto &p : a)p /= n;
	}
}
vector<int> fftMul(vector<int> a,vector<int> b){
	vector<cd> fa(all(a)),fb(all(b));
	int n=1;
	while(n<a.size()+b.size()){
		n*=2;
	}
	fa.resize(n);fb.resize(n);
	fft(fa);
	fft(fb);

	for(int i=0;i<n;++i){
		fa[i]*=fb[i];
	}
	fft(fa,1);

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

int solve() {
	ll n, i, j, k, m, x, y, z;
	cin >> n >> x >> y;
	int ma=2*x+2;
	m=x+10;
	vector<int> a(m);
	vector<int> b(ma+10);
	for(i=0;i<=n;++i){
		cin>>x;
		a[x]=1;
		b[ma-x]=1;
	}
	vector<int> c=fftMul(a,b);
	vector<int> del(m);
	for(i=ma+1;i<c.size();++i){
		if(!c[i])continue;
		if(y+i-ma<m){
			del[y+i-ma]=1;
		}
	}

	// trace(c);
	vector<int> ans(m,-1);
	for(int i=2;i<m;++i){
		for(j=i;j<m;j+=i){
			if(!del[i])continue;
			ans[j]=max(ans[j],i);
		}
	}

	int t;
	cin>>t;
	while(t--){
		cin>>x;
		// trace(x);
		x/=2;
		ll p=ans[x];
		if(p<0){
			cout<<"-1 ";
		}
		else{
			cout<<2*p<<" ";
		}
	}cout<<"\n";

	die();
}

void prec() {

}

// #define FILE_INPUT

int main() {

#ifndef ONLINE_JUDGE
	double _tBeg = clock();
#endif
	// Use "set_name".max_load_factor(0.25);"set_name".reserve(512); with unordered set
	// unordered_map<long long, ll, custom_hash> safe_map;
	// gp_hash_table<long long, ll, custom_hash> safe_hash_table;

	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#ifdef FILE_INPUT
	char *inputFile = "input.txt";
	char *outputFile = "fibs.txt";
	freopen(inputFile, "r", stdin);
	freopen(outputFile, "w", stdout);
#endif

	int t;
	t = 1;;
	prec();
	// cin >> t;

	int _case = 1;
	while (t--) {
		// cout<<"Case #"<<_case++<<": ";
		solve();
	}

#ifndef ONLINE_JUDGE
	double _tEnd = clock();
	// printf("\ntotal time %.6f\n",(_tEnd-_tBeg)/CLOCKS_PER_SEC);
#endif

	die();
}


/* Author: "Vimal Patel"
*  Problem URL:  https://codeforces.com/problemset/problem/1398/G
*/
#include <bits/stdc++.h>

#define INF 200000000000005
#define MOD 1000000007
#define ll long long int
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define pll pair<ll, ll>
#define vl vector<ll>
#define vll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define vvi vector<vector<int> >
#define vvii vector<vector<pair<int, int> > >
#define mii map<int, int>
#define vli vector<list<int> >
#define endl "\n"

using namespace std;

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

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

    for (int i = 1, j = 0; i < n; i++) {
        int bit = n >> 1;
        for (; j & bit; bit >>= 1)
            j ^= bit;
        j ^= bit;

        if (i < j)
            swap(a[i], a[j]);
    }

    for (int len = 2; len <= n; len <<= 1) {
        double ang = 2 * PI / len * (invert ? -1 : 1);
        cd wlen(cos(ang), sin(ang));
        for (int i = 0; i < n; i += len) {
            cd w(1);
            for (int j = 0; j < len / 2; j++) {
                cd u = a[i+j], v = a[i+j+len/2] * w;
                a[i+j] = u + v;
                a[i+j+len/2] = u - v;
                w *= wlen;
            }
        }
    }

    if (invert) {
        for (cd & x : a)
            x /= n;
    }
}

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;
}

int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

    int n, x, y, k=200001;
    cin >> n >> x >> y;

    vi a(n+1), ca(k+1, 0), cb(k+1, 0);
    for(auto& i:a){
        cin >> i;
        ca[i] = 1;
        cb[k-i] = 1;
    }

    auto cr = multiply(ca, cb);

    // cout << "[DEBUG] cr: ";
    // for(int i=0; i<cr.size(); i++)
    //     if(cr[i])
    //         cout << i-k << " ";
    // cout << endl;

    vi ds(x+1, 0);
    for(int i=0; i<=x; i++){
        ds[i] = cr[i+k];
    }
    ds[0] = 0;

    int q;
    cin >> q;
    for(int i=0; i<q; i++){
        int l;
        cin >> l;
        int j=sqrt(l);
        int ans=-1;
        while(j>=1){
            if(l%j==0){ //check if j indeed is a divisor of l
                int xl1 = (j>>1) - y;
                int xl2 = (l/j>>1) - y;
                //now check if xl can be found by ai-aj
                if(0<=xl1 and xl1<=x and ds[xl1]){
                    ans = max(ans, j);
                }else if(0<=xl2 and xl2<=x and ds[xl2]){
                    ans = max(ans, l/j);
                }
            }
            --j;
        }
        cout << ans << " ";
    }
    cout << endl;

    return 0;
}


/* Author: "Vimal Patel"
*  Problem URL:  https://codeforces.com/problemset/problem/1398/G
*/
#include <bits/stdc++.h>

#define INF 200000000000005
#define MOD 1000000007
#define ll long long int
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define pll pair<ll, ll>
#define vl vector<ll>
#define vll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define vvi vector<vector<int> >
#define vvii vector<vector<pair<int, int> > >
#define mii map<int, int>
#define vli vector<list<int> >
#define endl "\n"

using namespace std;

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

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

    for (int i = 1, j = 0; i < n; i++) {
        int bit = n >> 1;
        for (; j & bit; bit >>= 1)
            j ^= bit;
        j ^= bit;

        if (i < j)
            swap(a[i], a[j]);
    }

    for (int len = 2; len <= n; len <<= 1) {
        double ang = 2 * PI / len * (invert ? -1 : 1);
        cd wlen(cos(ang), sin(ang));
        for (int i = 0; i < n; i += len) {
            cd w(1);
            for (int j = 0; j < len / 2; j++) {
                cd u = a[i+j], v = a[i+j+len/2] * w;
                a[i+j] = u + v;
                a[i+j+len/2] = u - v;
                w *= wlen;
            }
        }
    }

    if (invert) {
        for (cd & x : a)
            x /= n;
    }
}

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;
}

int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

    int n, x, y, k=200001;
    cin >> n >> x >> y;

    vi a(n+1), ca(k+1, 0), cb(k+1, 0);
    for(auto& i:a){
        cin >> i;
        ca[i] = 1;
        cb[k-i] = 1;
    }

    auto cr = multiply(ca, cb);

    // cout << "[DEBUG] cr: ";
    // for(int i=0; i<cr.size(); i++)
    //     if(cr[i])
    //         cout << i-k << " ";
    // cout << endl;

    vi ds(x+1, 0);
    for(int i=0; i<=x; i++){
        ds[i] = cr[i+k];
    }
    ds[0] = 0;

    int q;
    cin >> q;
    for(int i=0; i<q; i++){
        int l;
        cin >> l;
        if(i==477){
            cout << l << " ";
            continue;
        }
        int j=sqrt(l);
        int ans=-1;
        while(j>=1){
            if(l%j==0){ //check if j indeed is a divisor of l
                int xl1 = (j>>1) - y;
                int xl2 = (l/j>>1) - y;
                //now check if xl can be found by ai-aj
                if(!(j&1) and 0<=xl1 and xl1<=x and ds[xl1]){
                    ans = max(ans, j);
                }else if(!(l/j & 1) and 0<=xl2 and xl2<=x and ds[xl2]){
                    ans = max(ans, l/j);
                }
            }
            --j;
        }
        cout << ans << " ";
    }
    cout << endl;

    return 0;
}


/* Author: "Vimal Patel"
*  Problem URL:  https://codeforces.com/problemset/problem/1398/G
*/
#include <bits/stdc++.h>

#define INF 200000000000005
#define MOD 1000000007
#define ll long long int
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define pll pair<ll, ll>
#define vl vector<ll>
#define vll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define vvi vector<vector<int> >
#define vvii vector<vector<pair<int, int> > >
#define mii map<int, int>
#define vli vector<list<int> >
#define endl "\n"

using namespace std;

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

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

    for (int i = 1, j = 0; i < n; i++) {
        int bit = n >> 1;
        for (; j & bit; bit >>= 1)
            j ^= bit;
        j ^= bit;

        if (i < j)
            swap(a[i], a[j]);
    }

    for (int len = 2; len <= n; len <<= 1) {
        double ang = 2 * PI / len * (invert ? -1 : 1);
        cd wlen(cos(ang), sin(ang));
        for (int i = 0; i < n; i += len) {
            cd w(1);
            for (int j = 0; j < len / 2; j++) {
                cd u = a[i+j], v = a[i+j+len/2] * w;
                a[i+j] = u + v;
                a[i+j+len/2] = u - v;
                w *= wlen;
            }
        }
    }

    if (invert) {
        for (cd & x : a)
            x /= n;
    }
}

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;
}

int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

    int n, x, y, k=200001;
    cin >> n >> x >> y;

    vi a(n+1), ca(k+1, 0), cb(k+1, 0);
    for(auto& i:a){
        cin >> i;
        ca[i] = 1;
        cb[k-i] = 1;
    }

    auto cr = multiply(ca, cb);

    // cout << "[DEBUG] cr: ";
    // for(int i=0; i<cr.size(); i++)
    //     if(cr[i])
    //         cout << i-k << " ";
    // cout << endl;

    vi ds(x+1, 0);
    for(int i=0; i<=x; i++){
        ds[i] = cr[i+k];
    }
    ds[0] = 0;

    int q;
    cin >> q;
    for(int i=0; i<q; i++){
        int l;
        cin >> l;
        int j=sqrt(l);
        int ans=-1;
        while(j>=1){
            if(!(j&1) and l%j==0){ //check if j indeed is a divisor of l
                int xl1 = (j>>1) - y;
                int xl2 = (l/j>>1) - y;
                //now check if xl can be found by ai-aj
                if(0<=xl1 and xl1<=x and ds[xl1]){
                    ans = max(ans, j);
                }else if(0<=xl2 and xl2<=x and ds[xl2]){
                    ans = max(ans, l/j);
                }
            }
            --j;
        }
        cout << ans << " ";
    }
    cout << endl;

    return 0;
}


/* Author: "Vimal Patel"
*  Problem URL:  https://codeforces.com/problemset/problem/1398/G
*/
#include <bits/stdc++.h>

#define INF 200000000000005
#define MOD 1000000007
#define ll long long int
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define pll pair<ll, ll>
#define vl vector<ll>
#define vll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define vvi vector<vector<int> >
#define vvii vector<vector<pair<int, int> > >
#define mii map<int, int>
#define vli vector<list<int> >
#define endl "\n"

using namespace std;

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

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

    for (int i = 1, j = 0; i < n; i++) {
        int bit = n >> 1;
        for (; j & bit; bit >>= 1)
            j ^= bit;
        j ^= bit;

        if (i < j)
            swap(a[i], a[j]);
    }

    for (int len = 2; len <= n; len <<= 1) {
        double ang = 2 * PI / len * (invert ? -1 : 1);
        cd wlen(cos(ang), sin(ang));
        for (int i = 0; i < n; i += len) {
            cd w(1);
            for (int j = 0; j < len / 2; j++) {
                cd u = a[i+j], v = a[i+j+len/2] * w;
                a[i+j] = u + v;
                a[i+j+len/2] = u - v;
                w *= wlen;
            }
        }
    }

    if (invert) {
        for (cd & x : a)
            x /= n;
    }
}

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;
}

int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

    int n, x, y, k=200001;
    cin >> n >> x >> y;

    vi a(n+1), ca(k+1, 0), cb(k+1, 0);
    for(auto& i:a){
        cin >> i;
        ca[i] = 1;
        cb[k-i] = 1;
    }

    auto cr = multiply(ca, cb);

    // cout << "[DEBUG] cr: ";
    // for(int i=0; i<cr.size(); i++)
    //     if(cr[i])
    //         cout << i-k << " ";
    // cout << endl;

    vi ds(x+1, 0);
    for(int i=0; i<=x; i++){
        ds[i] = cr[i+k];
    }
    ds[0] = 0;

    int q;
    cin >> q;
    for(int i=0; i<q; i++){
        int l;
        cin >> l;
        int j=sqrt(l);
        int ans=-1;
        while(j>=1){
            if(l%j==0){ //check if j indeed is a divisor of l
                int xl1 = (j>>1) - y;
                int xl2 = (l/j>>1) - y;
                //now check if xl can be found by ai-aj
                if(xl1>=0 and ds[xl1]){
                    ans = max(ans, j);
                }else if(xl2>=0 and ds[xl2]){
                    ans = max(ans, l/j);
                }
            }
            --j;
        }
        cout << ans << " ";
    }
    cout << endl;

    return 0;
}


/* Author: "Vimal Patel"
*  Problem URL:  https://codeforces.com/problemset/problem/1398/G
*/
#include <bits/stdc++.h>

#define INF 200000000000005
#define MOD 1000000007
#define ll long long int
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define pll pair<ll, ll>
#define vl vector<ll>
#define vll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define vvi vector<vector<int> >
#define vvii vector<vector<pair<int, int> > >
#define mii map<int, int>
#define vli vector<list<int> >
#define endl "\n"

using namespace std;

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

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

    for (int i = 1, j = 0; i < n; i++) {
        int bit = n >> 1;
        for (; j & bit; bit >>= 1)
            j ^= bit;
        j ^= bit;

        if (i < j)
            swap(a[i], a[j]);
    }

    for (int len = 2; len <= n; len <<= 1) {
        double ang = 2 * PI / len * (invert ? -1 : 1);
        cd wlen(cos(ang), sin(ang));
        for (int i = 0; i < n; i += len) {
            cd w(1);
            for (int j = 0; j < len / 2; j++) {
                cd u = a[i+j], v = a[i+j+len/2] * w;
                a[i+j] = u + v;
                a[i+j+len/2] = u - v;
                w *= wlen;
            }
        }
    }

    if (invert) {
        for (cd & x : a)
            x /= n;
    }
}

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;
}

int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

    int n, x, y, k=200001;
    cin >> n >> x >> y;

    vi a(n+1), ca(k+1, 0), cb(k+1, 0);
    for(auto& i:a){
        cin >> i;
        ca[i] = 1;
        cb[k-i] = 1;
    }

    auto cr = multiply(ca, cb);

    // cout << "[DEBUG] cr: ";
    // for(int i=0; i<cr.size(); i++)
    //     if(cr[i])
    //         cout << i-k << " ";
    // cout << endl;

    vi ds(x+1, 0);
    for(int i=0; i<=x; i++){
        ds[i] = cr[i+k];
    }
    ds[0] = 0;

    int q;
    cin >> q;
    for(int i=0; i<q; i++){
        int l;
        cin >> l;
        // if(i==477){
        //     cout << l << " ";
        //     continue;
        // }
        int j=sqrt(l);
        int ans=-1;
        while(j>=1){
            if(l%j==0){ //check if j indeed is a divisor of l
                int xl1 = (j>>1) - y;
                int xl2 = (l/j>>1) - y;
                //now check if xl can be found by ai-aj
                if(!(j&1) and 0<=xl1 and xl1<=x and ds[xl1]){
                    ans = max(ans, j);
                }
                if(!(l/j & 1) and 0<=xl2 and xl2<=x and ds[xl2]){
                    ans = max(ans, l/j);
                }
            }
            --j;
        }
        cout << ans << " ";
    }
    cout << endl;

    return 0;
}


/* Author: "Vimal Patel"
*  Problem URL:  https://codeforces.com/problemset/problem/1398/G
*/
#include <bits/stdc++.h>

#define INF 200000000000005
#define MOD 1000000007
#define ll long long int
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define pll pair<ll, ll>
#define vl vector<ll>
#define vll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define vvi vector<vector<int> >
#define vvii vector<vector<pair<int, int> > >
#define mii map<int, int>
#define vli vector<list<int> >
#define endl "\n"

using namespace std;

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

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

    for (int i = 1, j = 0; i < n; i++) {
        int bit = n >> 1;
        for (; j & bit; bit >>= 1)
            j ^= bit;
        j ^= bit;

        if (i < j)
            swap(a[i], a[j]);
    }

    for (int len = 2; len <= n; len <<= 1) {
        double ang = 2 * PI / len * (invert ? -1 : 1);
        cd wlen(cos(ang), sin(ang));
        for (int i = 0; i < n; i += len) {
            cd w(1);
            for (int j = 0; j < len / 2; j++) {
                cd u = a[i+j], v = a[i+j+len/2] * w;
                a[i+j] = u + v;
                a[i+j+len/2] = u - v;
                w *= wlen;
            }
        }
    }

    if (invert) {
        for (cd & x : a)
            x /= n;
    }
}

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;
}

int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

    int n, x, y, k=200001;
    cin >> n >> x >> y;

    vi a(n+1), ca(k+1, 0), cb(k+1, 0);
    for(auto& i:a){
        cin >> i;
        ca[i] = 1;
        cb[k-i] = 1;
    }

    auto cr = multiply(ca, cb);

    // cout << "[DEBUG] cr: ";
    // for(int i=0; i<cr.size(); i++)
    //     if(cr[i])
    //         cout << i-k << " ";
    // cout << endl;

    vi ds(x+1, 0);
    for(int i=0; i<=x; i++){
        ds[i] = cr[i+k];
    }
    ds[0] = 0;

    int q;
    cin >> q;
    for(int i=0; i<q; i++){
        int l;
        cin >> l;
        int j=sqrt(l);
        int ans=-1;
        while(j>=1){
            if(l%j==0){ //check if j indeed is a divisor of l
                int xl1 = (j>>1) - y;
                int xl2 = (l/j>>1) - y;
                //now check if xl can be found by ai-aj
                if(!(j&1) and 0<=xl1 and xl1<=x and ds[xl1]){
                    ans = max(ans, j);
                }else if(!(l/j & 1) and 0<=xl2 and xl2<=x and ds[xl2]){
                    ans = max(ans, l/j);
                }
            }
            --j;
        }
        cout << ans << " ";
    }
    cout << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef int Long;
typedef double Double;

struct CD {
	Double r, i;
	CD(Double r=0, Double i=0) : r(r) , i(i){}
	Double real() const{ return r; }
	void operator /= (const int c){ r /= c, i /= c;}
};
CD operator*(const CD& a, const CD& b){ return CD(a.r * b.r - a.i * b.i, a.r * b.i + a.i * b.r); }
CD operator+(const CD& a, const CD& b){ return CD(a.r + b.r, a.i + b.i); }
CD operator-(const CD& a, const CD& b){ return CD(a.r - b.r, a.i - b.i); }

const Long MX = (1 << 18);
const Double PI = acos(-1.0);
CD cp1[MX+9], cp2[MX+9];
Long R[MX+9];

void fft(CD* a, Long n, bool inverso){
	for(Long i = 0; i < n; i++){
		if(R[i] < i){
			swap(a[R[i]],a[i]);
		}
	}
	for(Long m = 2; m <= n; m <<= 1ll){
		Double z = 2 * PI / m * (inverso ? -1 : 1);
		CD wi = CD(cos(z),sin(z));
		for(Long j = 0; j < n; j += m){
			CD w(1);
			for(Long k = j, k2 = j + m/2; k2 < j + m; k++, k2++){
				CD u = a[k];
				CD v = a[k2] * w;
				a[k] = u + v;
				a[k2] = u - v;
				w = w * wi;
			}
		}
	}
	if(inverso){
		for(Long i = 0; i < n; i++){
			a[i] /= n;
		}
	}
	return;
}

vector<Long> multiply(vector<Long>& p1, vector<Long>& p2){
	Long n = p1.size() + p2.size() + 1;
	Long m = 1, cnt = 0;
	while(m <= n){
		m += m;
		cnt++;
	}
	for(Long i = 0; i < m; i++){
		R[i] = 0;
		for(Long j = 0; j < cnt; j++){
			R[i] = (R[i] << 1ll) | ((i>>j)&1);
		}
	}
	for(Long i = 0; i < m; i++){
		cp1[i] = cp2[i] = 0;
	}
	for(Long i = 0; i < p1.size(); i++){
		cp1[i] = p1[i];
	}
	for(Long i = 0; i < p2.size(); i++){
		cp2[i] = p2[i];
	}
	fft(cp1,m,false);
	fft(cp2,m,false);
	for(Long i = 0; i < m; i++){
		cp1[i] = cp1[i] * cp2[i];
	}
	fft(cp1,m,true);
	vector<Long> result;
	n -= 2;
	for(Long i = 0; i < n; i++){
		result.push_back(Long(cp1[i].real() + (cp1[i].real() > 0 ? 0.5 : -0.5)));
	}
	return result;
}

bool vis[MX];
bool used[MX];

void build(Long l, Long r){
	if(l >= r) return;
	Long med = (l + r) >> 1;
	vector<Long> A, B;
	A.resize(med-l+1,0);
	B.resize(r-med+1,0);
	for(Long i = med; i >= l; i--){
		if(vis[i]) A[med-i] = 1;
	}
	for(Long i = med; i <= r; i++){
		if(vis[i]) B[i-med] = 1;
	}
	vector<Long> AB = multiply(A,B);
	for(Long i = 0; i < AB.size(); i++){
		if(AB[i] != 0) used[i] = true;
	}
	build(l,med);
	build(med+1,r);
	return;
}

const Long K = 500001;

Long fact[K];

void extSieve(){
	for( Long i=2; i*i < K; ++i ){
		if( fact[ i ] == 0 ){
			for( Long j = i*i ; j < K ; j+=i ) if( fact[j ] == 0) fact[ j ] = i;
		}
	}
	for( Long i=2; i<K; ++i ){
		if( fact[ i ] == 0 ){
			fact[ i ] = i;
		}
	}
}

void solve(Long n, Long h){
	vector<Long> v;
	v.push_back(1);
	while( n > 1 ){
		Long f = fact[ n ];
		Long exp = 0;
		while( n % f == 0 ){
			n /= f;
			exp++;
		}
		Long sz = v.size();
		Long aux = f;
		for(Long i = 0; i < exp; i++){
			for(Long j = 0; j < sz; j++){
				v.push_back(aux*v[j]);
			}
			aux *= f;
		}
	}
	Long ans = -1;
	for(Long xx : v){
		if(xx > h && used[xx-h]){
			ans = max(xx*2,ans);
		}
	}
	cout << ans << " ";
	return;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout.precision(10);
	cout << fixed;

	extSieve();

	Long n, D, h, x;
	cin >> n >> D >> h;
	for(Long i = 0; i <= n; i++){
		cin >> x;
		vis[x] = true;
	}

	build(0,D);

	Long q;
	cin >> q;
	for(Long i = 0; i < q; i++){
		cin >> x;
		x /= 2;
		solve(x,h);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef int Long;
typedef double Double;

struct CD {
	Double r, i;
	CD(Double r=0, Double i=0) : r(r) , i(i){}
	Double real() const{ return r; }
	void operator /= (const int c){ r /= c, i /= c;}
};
CD operator*(const CD& a, const CD& b){ return CD(a.r * b.r - a.i * b.i, a.r * b.i + a.i * b.r); }
CD operator+(const CD& a, const CD& b){ return CD(a.r + b.r, a.i + b.i); }
CD operator-(const CD& a, const CD& b){ return CD(a.r - b.r, a.i - b.i); }

const Long MX = (1 << 19);
const Double PI = acos(-1.0);
CD cp1[MX+9], cp2[MX+9];
Long R[MX+9];

void fft(CD* a, Long n, bool inverso){
	for(Long i = 0; i < n; i++){
		if(R[i] < i){
			swap(a[R[i]],a[i]);
		}
	}
	for(Long m = 2; m <= n; m <<= 1ll){
		Double z = 2 * PI / m * (inverso ? -1 : 1);
		CD wi = CD(cos(z),sin(z));
		for(Long j = 0; j < n; j += m){
			CD w(1);
			for(Long k = j, k2 = j + m/2; k2 < j + m; k++, k2++){
				CD u = a[k];
				CD v = a[k2] * w;
				a[k] = u + v;
				a[k2] = u - v;
				w = w * wi;
			}
		}
	}
	if(inverso){
		for(Long i = 0; i < n; i++){
			a[i] /= n;
		}
	}
	return;
}

vector<Long> multiply(vector<Long>& p1, vector<Long>& p2){
	Long n = p1.size() + p2.size() + 1;
	Long m = 1, cnt = 0;
	while(m <= n){
		m += m;
		cnt++;
	}
	for(Long i = 0; i < m; i++){
		R[i] = 0;
		for(Long j = 0; j < cnt; j++){
			R[i] = (R[i] << 1ll) | ((i>>j)&1);
		}
	}
	for(Long i = 0; i < m; i++){
		cp1[i] = cp2[i] = 0;
	}
	for(Long i = 0; i < p1.size(); i++){
		cp1[i] = p1[i];
	}
	for(Long i = 0; i < p2.size(); i++){
		cp2[i] = p2[i];
	}
	fft(cp1,m,false);
	fft(cp2,m,false);
	for(Long i = 0; i < m; i++){
		cp1[i] = cp1[i] * cp2[i];
	}
	fft(cp1,m,true);
	vector<Long> result;
	n -= 2;
	for(Long i = 0; i < n; i++){
		result.push_back(Long(cp1[i].real() + (cp1[i].real() > 0 ? 0.5 : -0.5)));
	}
	return result;
}

bool vis[MX];
bool used[MX];

void build(Long l, Long r){
	if(l >= r) return;
	Long med = (l + r) >> 1;
	vector<Long> A, B;
	A.resize(med-l+1,0);
	B.resize(r-med+1,0);
	for(Long i = med; i >= l; i--){
		if(vis[i]) A[med-i] = 1;
	}
	for(Long i = med; i <= r; i++){
		if(vis[i]) B[i-med] = 1;
	}
	vector<Long> AB = multiply(A,B);
	for(Long i = 0; i < AB.size(); i++){
		if(AB[i] != 0) used[i] = true;
	}
	build(l,med);
	build(med+1,r);
	return;
}

Long fact[MX];

void extSieve(){
	for( Long i=2; i*i < MX; ++i ){
		if( fact[ i ] == 0 ){
			for( Long j = i*i ; j < MX ; j+=i ) if( fact[j ] == 0) fact[ j ] = i;
		}
	}
	for( Long i=2; i<MX; ++i ){
		if( fact[ i ] == 0 ){
			fact[ i ] = i;
		}
	}
}

void solve(Long n, Long h){
	vector<Long> v;
	v.push_back(1);
	while( n > 1 ){
		Long f = fact[ n ];
		Long exp = 0;
		while( n % f == 0 ){
			n /= f;
			exp++;
		}
		Long sz = v.size();
		Long aux = f;
		for(Long i = 0; i < exp; i++){
			for(Long j = 0; j < sz; j++){
				v.push_back(aux*v[j]);
			}
			aux *= f;
		}
	}
	Long ans = -1;
	for(Long xx : v){
		if(xx > h && used[xx-h]){
			ans = max(xx*2,ans);
		}
	}
	cout << ans << " ";
	return;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout.precision(10);
	cout << fixed;

	extSieve();

	Long n, D, h, x;
	cin >> n >> D >> h;
	for(Long i = 0; i <= n; i++){
		cin >> x;
		vis[x] = true;
	}

	build(0,D);

	Long q;
	cin >> q;
	for(Long i = 0; i < q; i++){
		cin >> x;
		x /= 2;
		solve(x,h);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef int Long;
typedef double Double;

struct CD {
	Double r, i;
	CD(Double r=0, Double i=0) : r(r) , i(i){}
	Double real() const{ return r; }
	void operator /= (const int c){ r /= c, i /= c;}
};
CD operator*(const CD& a, const CD& b){ return CD(a.r * b.r - a.i * b.i, a.r * b.i + a.i * b.r); }
CD operator+(const CD& a, const CD& b){ return CD(a.r + b.r, a.i + b.i); }
CD operator-(const CD& a, const CD& b){ return CD(a.r - b.r, a.i - b.i); }

const Long MX = (1 << 19);
const Double PI = acos(-1.0);
CD cp1[MX+9], cp2[MX+9];
Long R[MX+9];

void fft(CD* a, Long n, bool inverso){
	for(Long i = 0; i < n; i++){
		if(R[i] < i){
			swap(a[R[i]],a[i]);
		}
	}
	for(Long m = 2; m <= n; m <<= 1ll){
		Double z = 2 * PI / m * (inverso ? -1 : 1);
		CD wi = CD(cos(z),sin(z));
		for(Long j = 0; j < n; j += m){
			CD w(1);
			for(Long k = j, k2 = j + m/2; k2 < j + m; k++, k2++){
				CD u = a[k];
				CD v = a[k2] * w;
				a[k] = u + v;
				a[k2] = u - v;
				w = w * wi;
			}
		}
	}
	if(inverso){
		for(Long i = 0; i < n; i++){
			a[i] /= n;
		}
	}
	return;
}

vector<Long> multiply(vector<Long>& p1, vector<Long>& p2){
	Long n = p1.size() + p2.size() + 1;
	Long m = 1, cnt = 0;
	while(m <= n){
		m += m;
		cnt++;
	}
	for(Long i = 0; i < m; i++){
		R[i] = 0;
		for(Long j = 0; j < cnt; j++){
			R[i] = (R[i] << 1ll) | ((i>>j)&1);
		}
	}
	for(Long i = 0; i < m; i++){
		cp1[i] = cp2[i] = 0;
	}
	for(Long i = 0; i < p1.size(); i++){
		cp1[i] = p1[i];
	}
	for(Long i = 0; i < p2.size(); i++){
		cp2[i] = p2[i];
	}
	fft(cp1,m,false);
	fft(cp2,m,false);
	for(Long i = 0; i < m; i++){
		cp1[i] = cp1[i] * cp2[i];
	}
	fft(cp1,m,true);
	vector<Long> result;
	n -= 2;
	for(Long i = 0; i < n; i++){
		result.push_back(Long(cp1[i].real() + (cp1[i].real() > 0 ? 0.5 : -0.5)));
	}
	return result;
}

bool vis[MX];
bool used[MX];

void build(Long l, Long r){
	if(l >= r) return;
	Long med = (l + r) >> 1;
	vector<Long> A, B;
	A.resize(med-l+1,0);
	B.resize(r-med+1,0);
	for(Long i = med; i >= l; i--){
		if(vis[i]) A[med-i] = 1;
	}
	for(Long i = med; i <= r; i++){
		if(vis[i]) B[i-med] = 1;
	}
	vector<Long> AB = multiply(A,B);
	for(Long i = 0; i < AB.size(); i++){
		if(AB[i] != 0) used[i] = true;
	}
	build(l,med);
	build(med+1,r);
	return;
}

Long fact[MX];

void extSieve(){
	for( Long i=2; i*i < MX; ++i ){
		if( fact[ i ] == 0 ){
			for( Long j = i*i ; j < MX ; j+=i ) if( fact[j ] == 0) fact[ j ] = i;
		}
	}
	for( Long i=2; i<MX; ++i ){
		if( fact[ i ] == 0 ){
			fact[ i ] = i;
		}
	}
}

void solve(Long n, Long h){
	vector<Long> v;
	v.push_back(1);
	while( n > 1 ){
		Long f = fact[ n ];
		Long exp = 0;
		while( n % f == 0 ){
			n /= f;
			exp++;
		}
		Long sz = v.size();
		Long aux = f;
		for(Long i = 0; i < exp; i++){
			for(Long j = 0; j < sz; j++){
				v.push_back(aux*v[j]);
			}
			if(i != exp-1) aux *= f;
		}
	}
	Long ans = -1;
	for(Long xx : v){
		if(xx > h && used[xx-h]){
			ans = max(xx*2,ans);
		}
	}
	cout << ans << " ";
	return;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout.precision(10);
	cout << fixed;

	extSieve();

	Long n, D, h, x;
	cin >> n >> D >> h;
	for(Long i = 0; i <= n; i++){
		cin >> x;
		vis[x] = true;
	}

	build(0,D);

	Long q;
	cin >> q;
	for(Long i = 0; i < q; i++){
		cin >> x;
		x /= 2;
		solve(x,h);
	}
	return 0;
}


/**
 *  author: ivanzuki
 *  created: Fri Sep 18 2020
**/
#include <bits/stdc++.h>

using namespace std;

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template <typename T>
T inverse(T a, T m) {
  T u = 0, v = 1;
  while (a != 0) {
    T t = m / a;
    m -= t * a; swap(a, m);
    u -= t * v; swap(u, v);
  }
  assert(m == 1);
  return u;
}

template <typename T>
class Modular {
 public:
  using Type = typename decay<decltype(T::value)>::type;

  constexpr Modular() : value() {}
  template <typename U>
  Modular(const U& x) {
    value = normalize(x);
  }

  template <typename U>
  static Type normalize(const U& x) {
    Type v;
    if (-mod() <= x && x < mod()) v = static_cast<Type>(x);
    else v = static_cast<Type>(x % mod());
    if (v < 0) v += mod();
    return v;
  }

  const Type& operator()() const { return value; }
  template <typename U>
  explicit operator U() const { return static_cast<U>(value); }
  constexpr static Type mod() { return T::value; }

  Modular& operator+=(const Modular& other) { if ((value += other.value) >= mod()) value -= mod(); return *this; }
  Modular& operator-=(const Modular& other) { if ((value -= other.value) < 0) value += mod(); return *this; }
  template <typename U> Modular& operator+=(const U& other) { return *this += Modular(other); }
  template <typename U> Modular& operator-=(const U& other) { return *this -= Modular(other); }
  Modular& operator++() { return *this += 1; }
  Modular& operator--() { return *this -= 1; }
  Modular operator++(int) { Modular result(*this); *this += 1; return result; }
  Modular operator--(int) { Modular result(*this); *this -= 1; return result; }
  Modular operator-() const { return Modular(-value); }

  template <typename U = T>
  typename enable_if<is_same<typename Modular<U>::Type, int>::value, Modular>::type& operator*=(const Modular& rhs) {
#ifdef _WIN32
    uint64_t x = static_cast<int64_t>(value) * static_cast<int64_t>(rhs.value);
    uint32_t xh = static_cast<uint32_t>(x >> 32), xl = static_cast<uint32_t>(x), d, m;
    asm(
      "divl %4; \n\t"
      : "=a" (d), "=d" (m)
      : "d" (xh), "a" (xl), "r" (mod())
    );
    value = m;
#else
    value = normalize(static_cast<int64_t>(value) * static_cast<int64_t>(rhs.value));
#endif
    return *this;
  }
  template <typename U = T>
  typename enable_if<is_same<typename Modular<U>::Type, int64_t>::value, Modular>::type& operator*=(const Modular& rhs) {
    int64_t q = static_cast<int64_t>(static_cast<long double>(value) * rhs.value / mod());
    value = normalize(value * rhs.value - q * mod());
    return *this;
  }
  template <typename U = T>
  typename enable_if<!is_integral<typename Modular<U>::Type>::value, Modular>::type& operator*=(const Modular& rhs) {
    value = normalize(value * rhs.value);
    return *this;
  }

  Modular& operator/=(const Modular& other) { return *this *= Modular(inverse(other.value, mod())); }

  template <typename U>
  friend const Modular<U>& abs(const Modular<U>& v) { return v; }

  template <typename U>
  friend bool operator==(const Modular<U>& lhs, const Modular<U>& rhs);

  template <typename U>
  friend bool operator<(const Modular<U>& lhs, const Modular<U>& rhs);

  template <typename U>
  friend std::istream& operator>>(std::istream& stream, Modular<U>& number);

 private:
  Type value;
};

template <typename T> bool operator==(const Modular<T>& lhs, const Modular<T>& rhs) { return lhs.value == rhs.value; }
template <typename T, typename U> bool operator==(const Modular<T>& lhs, U rhs) { return lhs == Modular<T>(rhs); }
template <typename T, typename U> bool operator==(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) == rhs; }

template <typename T> bool operator!=(const Modular<T>& lhs, const Modular<T>& rhs) { return !(lhs == rhs); }
template <typename T, typename U> bool operator!=(const Modular<T>& lhs, U rhs) { return !(lhs == rhs); }
template <typename T, typename U> bool operator!=(U lhs, const Modular<T>& rhs) { return !(lhs == rhs); }

template <typename T> bool operator<(const Modular<T>& lhs, const Modular<T>& rhs) { return lhs.value < rhs.value; }

template <typename T> Modular<T> operator+(const Modular<T>& lhs, const Modular<T>& rhs) { return Modular<T>(lhs) += rhs; }
template <typename T, typename U> Modular<T> operator+(const Modular<T>& lhs, U rhs) { return Modular<T>(lhs) += rhs; }
template <typename T, typename U> Modular<T> operator+(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) += rhs; }

template <typename T> Modular<T> operator-(const Modular<T>& lhs, const Modular<T>& rhs) { return Modular<T>(lhs) -= rhs; }
template <typename T, typename U> Modular<T> operator-(const Modular<T>& lhs, U rhs) { return Modular<T>(lhs) -= rhs; }
template <typename T, typename U> Modular<T> operator-(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) -= rhs; }

template <typename T> Modular<T> operator*(const Modular<T>& lhs, const Modular<T>& rhs) { return Modular<T>(lhs) *= rhs; }
template <typename T, typename U> Modular<T> operator*(const Modular<T>& lhs, U rhs) { return Modular<T>(lhs) *= rhs; }
template <typename T, typename U> Modular<T> operator*(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) *= rhs; }

template <typename T> Modular<T> operator/(const Modular<T>& lhs, const Modular<T>& rhs) { return Modular<T>(lhs) /= rhs; }
template <typename T, typename U> Modular<T> operator/(const Modular<T>& lhs, U rhs) { return Modular<T>(lhs) /= rhs; }
template <typename T, typename U> Modular<T> operator/(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) /= rhs; }

template<typename T, typename U>
Modular<T> power(const Modular<T>& a, const U& b) {
  assert(b >= 0);
  Modular<T> x = a, res = 1;
  U p = b;
  while (p > 0) {
    if (p & 1) res *= x;
    x *= x;
    p >>= 1;
  }
  return res;
}

template <typename T>
bool IsZero(const Modular<T>& number) {
  return number() == 0;
}

template <typename T>
string to_string(const Modular<T>& number) {
  return to_string(number());
}

template <typename T>
std::ostream& operator<<(std::ostream& stream, const Modular<T>& number) {
  return stream << number();
}

template <typename T>
std::istream& operator>>(std::istream& stream, Modular<T>& number) {
  typename common_type<typename Modular<T>::Type, int64_t>::type x;
  stream >> x;
  number.value = Modular<T>::normalize(x);
  return stream;
}

/*
using ModType = int;

struct VarMod { static ModType value; };
ModType VarMod::value;
ModType& md = VarMod::value;
using Mint = Modular<VarMod>;
*/

constexpr int md = 998244353;
using Mint = Modular<std::integral_constant<decay<decltype(md)>::type, md>>;

// make it understandable one day...
namespace fft {

typedef double dbl;

struct num {
  dbl x, y;
  num() { x = y = 0; }
  num(dbl x_, dbl y_) : x(x_), y(y_) {}
};

inline num operator+(num a, num b) { return num(a.x + b.x, a.y + b.y); }
inline num operator-(num a, num b) { return num(a.x - b.x, a.y - b.y); }
inline num operator*(num a, num b) { return num(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x); }
inline num conj(num a) { return num(a.x, -a.y); }

int base = 1;
vector<num> roots = {{0, 0}, {1, 0}};
vector<int> rev = {0, 1};

const dbl PI = static_cast<dbl>(acosl(-1.0));

void ensure_base(int nbase) {
  if (nbase <= base) {
    return;
  }
  rev.resize(1 << nbase);
  for (int i = 0; i < (1 << nbase); i++) {
    rev[i] = (rev[i >> 1] >> 1) + ((i & 1) << (nbase - 1));
  }
  roots.resize(1 << nbase);
  while (base < nbase) {
    dbl angle = 2 * PI / (1 << (base + 1));
//      num z(cos(angle), sin(angle));
    for (int i = 1 << (base - 1); i < (1 << base); i++) {
      roots[i << 1] = roots[i];
//        roots[(i << 1) + 1] = roots[i] * z;
      dbl angle_i = angle * (2 * i + 1 - (1 << base));
      roots[(i << 1) + 1] = num(cos(angle_i), sin(angle_i));
    }
    base++;
  }
}

void fft(vector<num>& a, int n = -1) {
  if (n == -1) {
    n = (int) a.size();
  }
  assert((n & (n - 1)) == 0);
  int zeros = __builtin_ctz(n);
  ensure_base(zeros);
  int shift = base - zeros;
  for (int i = 0; i < n; i++) {
    if (i < (rev[i] >> shift)) {
      swap(a[i], a[rev[i] >> shift]);
    }
  }
  for (int k = 1; k < n; k <<= 1) {
    for (int i = 0; i < n; i += 2 * k) {
      for (int j = 0; j < k; j++) {
        num z = a[i + j + k] * roots[j + k];
        a[i + j + k] = a[i + j] - z;
        a[i + j] = a[i + j] + z;
      }
    }
  }
}

vector<num> fa, fb;

vector<int64_t> square(const vector<int>& a) {
  if (a.empty()) {
    return {};
  }
  int need = (int) a.size() + (int) a.size() - 1;
  int nbase = 1;
  while ((1 << nbase) < need) nbase++;
  ensure_base(nbase);
  int sz = 1 << nbase;
  if ((sz >> 1) > (int) fa.size()) {
    fa.resize(sz >> 1);
  }
  for (int i = 0; i < (sz >> 1); i++) {
    int x = (2 * i < (int) a.size() ? a[2 * i] : 0);
    int y = (2 * i + 1 < (int) a.size() ? a[2 * i + 1] : 0);
    fa[i] = num(x, y);
  }
  fft(fa, sz >> 1);
  num r(1.0 / (sz >> 1), 0.0);
  for (int i = 0; i <= (sz >> 2); i++) {
    int j = ((sz >> 1) - i) & ((sz >> 1) - 1);
    num fe = (fa[i] + conj(fa[j])) * num(0.5, 0);
    num fo = (fa[i] - conj(fa[j])) * num(0, -0.5);
    num aux = fe * fe + fo * fo * roots[(sz >> 1) + i] * roots[(sz >> 1) + i];
    num tmp = fe * fo;
    fa[i] = r * (conj(aux) + num(0, 2) * conj(tmp));
    fa[j] = r * (aux + num(0, 2) * tmp);
  }
  fft(fa, sz >> 1);
  vector<int64_t> res(need);
  for (int i = 0; i < need; i++) {
    res[i] = llround(i % 2 == 0 ? fa[i >> 1].x : fa[i >> 1].y);
  }
  return res;
}

vector<int64_t> multiply(const vector<int>& a, const vector<int>& b) {
  if (a.empty() || b.empty()) {
    return {};
  }
  if (a == b) {
    return square(a);
  }
  int need = (int) a.size() + (int) b.size() - 1;
  int nbase = 1;
  while ((1 << nbase) < need) nbase++;
  ensure_base(nbase);
  int sz = 1 << nbase;
  if (sz > (int) fa.size()) {
    fa.resize(sz);
  }
  for (int i = 0; i < sz; i++) {
    int x = (i < (int) a.size() ? a[i] : 0);
    int y = (i < (int) b.size() ? b[i] : 0);
    fa[i] = num(x, y);
  }
  fft(fa, sz);
  num r(0, -0.25 / (sz >> 1));
  for (int i = 0; i <= (sz >> 1); i++) {
    int j = (sz - i) & (sz - 1);
    num z = (fa[j] * fa[j] - conj(fa[i] * fa[i])) * r;
    fa[j] = (fa[i] * fa[i] - conj(fa[j] * fa[j])) * r;
    fa[i] = z;
  }
  for (int i = 0; i < (sz >> 1); i++) {
    num A0 = (fa[i] + fa[i + (sz >> 1)]) * num(0.5, 0);
    num A1 = (fa[i] - fa[i + (sz >> 1)]) * num(0.5, 0) * roots[(sz >> 1) + i];
    fa[i] = A0 + A1 * num(0, 1);
  }
  fft(fa, sz >> 1);
  vector<int64_t> res(need);
  for (int i = 0; i < need; i++) {
    res[i] = llround(i % 2 == 0 ? fa[i >> 1].x : fa[i >> 1].y);
  }
  return res;
}

vector<int> multiply_mod(const vector<int>& a, const vector<int>& b, int m) {
  if (a.empty() || b.empty()) {
    return {};
  }
  int eq = (a.size() == b.size() && a == b);
  int need = (int) a.size() + (int) b.size() - 1;
  int nbase = 0;
  while ((1 << nbase) < need) nbase++;
  ensure_base(nbase);
  int sz = 1 << nbase;
  if (sz > (int) fa.size()) {
    fa.resize(sz);
  }
  for (int i = 0; i < (int) a.size(); i++) {
    int x = (a[i] % m + m) % m;
    fa[i] = num(x & ((1 << 15) - 1), x >> 15);
  }
  fill(fa.begin() + a.size(), fa.begin() + sz, num {0, 0});
  fft(fa, sz);
  if (sz > (int) fb.size()) {
    fb.resize(sz);
  }
  if (eq) {
    copy(fa.begin(), fa.begin() + sz, fb.begin());
  } else {
    for (int i = 0; i < (int) b.size(); i++) {
      int x = (b[i] % m + m) % m;
      fb[i] = num(x & ((1 << 15) - 1), x >> 15);
    }
    fill(fb.begin() + b.size(), fb.begin() + sz, num {0, 0});
    fft(fb, sz);
  }
  dbl ratio = 0.25 / sz;
  num r2(0, -1);
  num r3(ratio, 0);
  num r4(0, -ratio);
  num r5(0, 1);
  for (int i = 0; i <= (sz >> 1); i++) {
    int j = (sz - i) & (sz - 1);
    num a1 = (fa[i] + conj(fa[j]));
    num a2 = (fa[i] - conj(fa[j])) * r2;
    num b1 = (fb[i] + conj(fb[j])) * r3;
    num b2 = (fb[i] - conj(fb[j])) * r4;
    if (i != j) {
      num c1 = (fa[j] + conj(fa[i]));
      num c2 = (fa[j] - conj(fa[i])) * r2;
      num d1 = (fb[j] + conj(fb[i])) * r3;
      num d2 = (fb[j] - conj(fb[i])) * r4;
      fa[i] = c1 * d1 + c2 * d2 * r5;
      fb[i] = c1 * d2 + c2 * d1;
    }
    fa[j] = a1 * b1 + a2 * b2 * r5;
    fb[j] = a1 * b2 + a2 * b1;
  }
  fft(fa, sz);
  fft(fb, sz);
  vector<int> res(need);
  for (int i = 0; i < need; i++) {
    int64_t aa = llround(fa[i].x);
    int64_t bb = llround(fb[i].x);
    int64_t cc = llround(fa[i].y);
    res[i] = static_cast<int>((aa + ((bb % m) << 15) + ((cc % m) << 30)) % m);
  }
  return res;
}

}  // namespace fft

template <typename T>
typename enable_if<is_same<typename Modular<T>::Type, int>::value, vector<Modular<T>>>::type operator*(
    const vector<Modular<T>>& a,
    const vector<Modular<T>>& b) {
  if (a.empty() || b.empty()) {
    return {};
  }
  if (min(a.size(), b.size()) < 150) {
    vector<Modular<T>> c(a.size() + b.size() - 1, 0);
    for (int i = 0; i < (int) a.size(); i++) {
      for (int j = 0; j < (int) b.size(); j++) {
        c[i + j] += a[i] * b[j];
      }
    }
    return c;
  }
  vector<int> a_mul(a.size());
  for (int i = 0; i < (int) a.size(); i++) {
    a_mul[i] = static_cast<int>(a[i]);
  }
  vector<int> b_mul(b.size());
  for (int i = 0; i < (int) b.size(); i++) {
    b_mul[i] = static_cast<int>(b[i]);
  }
  vector<int> c_mul = fft::multiply_mod(a_mul, b_mul, T::value);
  vector<Modular<T>> c(c_mul.size());
  for (int i = 0; i < (int) c.size(); i++) {
    c[i] = c_mul[i];
  }
  return c;
}

template <typename T>
typename enable_if<is_same<typename Modular<T>::Type, int>::value, vector<Modular<T>>>::type& operator*=(
    vector<Modular<T>>& a,
    const vector<Modular<T>>& b) {
  return a = a * b;
}

const int K = 200010;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, x, y;
  cin >> n >> x >> y;
  vector<int> a(n + 1);
  for (int i = 0; i <= n; i++) {
    cin >> a[i];
  }
  vector<int> b = a;
  for (int i = 0; i <= n; i++) {
    b[i] = K - a[i];
  }
  vector<int> a_ind(K + 1);
  vector<int> b_ind(K + 1);
  for (int i = 0; i <= n; i++) {
    a_ind[a[i]] = 1;
    b_ind[b[i]] = 1;
  }
  vector<long long> c_ind = fft::multiply(a_ind, b_ind);
  const int Q = 1000010;
  vector<int> can(Q);
  for (int i = 0; i < (int) c_ind.size(); i++) {
    if (c_ind[i] != 0 && i - K > 0) {
      can[i - K + y] = i - K + y;
    }
  }
  for (int d = 1; d < Q; d++) {
    for (int m = d; m < Q; m += d) {
      can[m] = max(can[m], can[d]);
    }
  }
  int qq;
  cin >> qq;
  while (qq--) {
    int x;
    cin >> x;
    if (can[x / 2] > 0) {
      cout << 2 * can[x / 2] << ' ';
    } else {
      cout << "-1" << ' ';
    }
  }
  cout << '\n';
  return 0;
}


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

#define REP(i, n) for(int i = 0; i < (n); i++)

const double pi = acos(-1);

void fft(vector <complex <double> > &a, bool inv) {
	int n = (int)a.size();
	if(n == 1) return;
	vector <complex <double> > parni, neparni;
	for(int i = 0; i < n / 2; i++) {
		parni.push_back(a[i * 2]);
		neparni.push_back(a[i * 2 + 1]);
	}
	fft(parni, inv);
	fft(neparni, inv);
	complex <double> w = 1., wn = polar(1., (inv ? -2 : 2) * pi / n);
	for(int i = 0; i < n / 2; i++) {
		a[i] = parni[i] + w * neparni[i];
		a[i + n / 2] = parni[i] - w * neparni[i];
		if(inv) {
			a[i] /= 2;
			a[i + n / 2] /= 2;
		}
		w *= wn;
	}
	return;
}

vector <int> mult_pol(vector <int> &a, vector <int> &b) {
	int n = 1;
	while((int)a.size() + (int)b.size() - 1 > n) n *= 2;
	vector <complex <double> > c_a(n), c_b(n);
	for(int i = 0; i < (int)a.size(); i++) c_a[i] = a[i];
	for(int i = 0; i < (int)b.size(); i++) c_b[i] = b[i];
	c_a.resize(n, 0); c_b.resize(n, 0);
	fft(c_a, 0); fft(c_b, 0);
	for(int i = 0; i < n; i++) c_a[i] = c_a[i] * c_b[i];
	fft(c_a, 1);
	vector <int> c(n);
	for(int i = 0; i < n; i++) c[i] = round(c_a[i].real());
	return c;
}

int sol[1000100] = {0};

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, x, y, q, broj;
	cin >> n >> x >> y;
	n++;
	vector <int> a(x + 1, 0), b(x + 1, 0);
	REP(i, n) {
		cin >> broj;
		a[broj] = 1;
		b[x - broj] = 1;
	}
	a = mult_pol(a, b);
	for(int i = x + 1; i < (int)a.size(); i++) {
		if(a[i]) {
			for(int j = (i - x) * 2 + y * 2; j < 1000010; j += (i - x) * 2 + y * 2) sol[j] = (i - x) * 2 + y * 2;
		}
	}
	cin >> q;
	REP(qq, q) {
		cin >> n;
		if(sol[n]) cout << sol[n] << " ";
		else cout << -1 << " ";
	}
	cout << endl;
	return 0;
}


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

#define REP(i, n) for(int i = 0; i < (n); i++)

const double pi = acos(-1);

void fft(vector <complex <double> > &a, bool inv) {
	int n = (int)a.size();
	if(n == 1) return;
	vector <complex <double> > parni, neparni;
	for(int i = 0; i < n / 2; i++) {
		parni.push_back(a[i * 2]);
		neparni.push_back(a[i * 2 + 1]);
	}
	fft(parni, inv);
	fft(neparni, inv);
	complex <double> w = 1., wn = polar(1., (inv ? -2 : 2) * pi / n);
	for(int i = 0; i < n / 2; i++) {
		a[i] = parni[i] + w * neparni[i];
		a[i + n / 2] = parni[i] - w * neparni[i];
		if(inv) {
			a[i] /= 2;
			a[i + n / 2] /= 2;
		}
		w *= wn;
	}
	return;
}

vector <int> mult_pol(vector <int> &a, vector <int> &b) {
	int n = 1;
	while((int)a.size() + (int)b.size() - 1 > n) n *= 2;
	vector <complex <double> > c_a(n), c_b(n);
	for(int i = 0; i < (int)a.size(); i++) c_a[i] = (double)a[i];
	for(int i = 0; i < (int)b.size(); i++) c_b[i] = (double)b[i];
	c_a.resize(n, 0); c_b.resize(n, 0);
	fft(c_a, 0); fft(c_b, 0);
	vector <complex <double> > c_c(n);
	for(int i = 0; i < n; i++) c_c[i] = c_a[i] * c_b[i];
	fft(c_c, 1);
	vector <int> c(n);
	for(int i = 0; i < n; i++) c[i] = round(c_c[i].real());
	return c;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, x, y, q, broj;
	cin >> n >> x >> y;
	n++;
	vector <int> a(x + 1, 0), b(x + 1, 0);
	REP(i, n) {
		cin >> broj;
		a[broj] = 1;
		b[x - broj] = 1;
	}
	a = mult_pol(a, b);
	int sol[1000100] = {0};
	for(int i = x + 1; i < (int)a.size(); i++) {
		if(a[i]) {
			for(int j = (i - x) * 2 + y * 2; j < 1000010; j += (i - x) * 2 + y * 2) sol[j] = (i - x) * 2 + y * 2;
		}
	}
	cin >> q;
	REP(qq, q) {
		cin >> n;
		if(sol[n]) cout << sol[n] << " ";
		else cout << -1 << " ";
	}
	cout << endl;
	return 0;
}


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

#define REP(i, n) for(int i = 0; i < (n); i++)

typedef complex<double> C;
void fft(vector <C> &a) {
	int n = a.size(), L = 31 - __builtin_clz(n);
	static vector <complex <double> > R(2, 1);
	static vector <C> rt(2, 1);  // (^ 10% faster if double)
	for(static int k = 2; k < n; k *= 2) {
		R.resize(n); rt.resize(n);
		auto x = polar(1.0, acos(-1.0) / k);
		for(int i = k; i < 2 * k; ++i) rt[i] = R[i] = i & 1 ? R[i/2] * x : R[i/2];
	}
	vector <int> rev(n);
	for(int i = 0; i < n; ++i) rev[i] = (rev[i / 2] | (i & 1) << L) / 2;
	for(int i = 0; i < n; ++i) if(i < rev[i]) swap(a[i], a[rev[i]]);
	for(int k = 1; k < n; k *= 2)
		for(int i = 0; i < n; i += 2 * k) for(int j = 0; j < k; ++j) {
			 //C z = rt[j+k] * a[i+j+k]; // (25% faster if hand-rolled)  /// include-line
			auto x = (double *)&rt[j+k], y = (double *)&a[i+j+k];        /// exclude-line
			C z(x[0]*y[0] - x[1]*y[1], x[0]*y[1] + x[1]*y[0]);           /// exclude-line
			a[i + j + k] = a[i + j] - z;
			a[i + j] += z;
		}
}
vector <double> mult_pol(const vector <double> &a, const vector <double> &b) {
	if (a.empty() || b.empty()) return {};
	vector <double> res(a.size() + b.size() - 1);
	int L = 32 - __builtin_clz(res.size()), n = 1 << L;
	vector<C> in(n), out(n);
	copy(begin(a), end(a), begin(in));
	for(int i = 0; i < (int)b.size(); ++i) in[i].imag(b[i]);
	fft(in);
	for(C& x : in) x *= x;
	for(int i=0;i<n;++i) out[i] = in[-i & (n - 1)] - conj(in[i]);
	fft(out);
	for(int i = 0; i < (int)res.size(); ++i) res[i] = imag(out[i]) / (4 * n);
	return res;
}

int sol[1000100] = {0};

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, x, y, q, broj;
	cin >> n >> x >> y;
	n++;
	vector <double> a(x + 1, 0), b(x + 1, 0);
	REP(i, n) {
		cin >> broj;
		a[broj] = 1;
		b[x - broj] = 1;
	}
	a = mult_pol(a, b);
	for(int i = x + 1; i < (int)a.size(); i++) {
		if(a[i] > 0.5) {
			for(int j = (i - x) * 2 + y * 2; j < 1000010; j += (i - x) * 2 + y * 2) sol[j] = (i - x) * 2 + y * 2;
		}
	}
	cin >> q;
	REP(qq, q) {
		cin >> n;
		if(sol[n]) cout << sol[n] << " ";
		else cout << -1 << " ";
	}
	cout << endl;
	return 0;
}


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

#define REP(i, n) for(int i = 0; i < (n); i++)

typedef complex<double> C;
void fft(vector <C> &a) {
	int n = a.size(), L = 31 - __builtin_clz(n);
	static vector <complex <long double> > R(2, 1);
	static vector <C> rt(2, 1);  // (^ 10% faster if double)
	for(static int k = 2; k < n; k *= 2) {
		R.resize(n); rt.resize(n);
		auto x = polar(1.0L, acos(-1.0L) / k);
		for(int i = k; i < 2 * k; ++i) rt[i] = R[i] = i & 1 ? R[i/2] * x : R[i/2];
	}
	vector <int> rev(n);
	for(int i = 0; i < n; ++i) rev[i] = (rev[i / 2] | (i & 1) << L) / 2;
	for(int i = 0; i < n; ++i) if(i < rev[i]) swap(a[i], a[rev[i]]);
	for(int k = 1; k < n; k *= 2)
		for(int i = 0; i < n; i += 2 * k) for(int j = 0; j < k; ++j) {
			 //C z = rt[j+k] * a[i+j+k]; // (25% faster if hand-rolled)  /// include-line
			auto x = (double *)&rt[j+k], y = (double *)&a[i+j+k];        /// exclude-line
			C z(x[0]*y[0] - x[1]*y[1], x[0]*y[1] + x[1]*y[0]);           /// exclude-line
			a[i + j + k] = a[i + j] - z;
			a[i + j] += z;
		}
}
vector <double> mult_pol(const vector <double> &a, const vector <double> &b) {
	if (a.empty() || b.empty()) return {};
	vector <double> res(a.size() + b.size() - 1);
	int L = 32 - __builtin_clz(res.size()), n = 1 << L;
	vector<C> in(n), out(n);
	copy(begin(a), end(a), begin(in));
	for(int i = 0; i < (int)b.size(); ++i) in[i].imag(b[i]);
	fft(in);
	for(C& x : in) x *= x;
	for(int i=0;i<n;++i) out[i] = in[-i & (n - 1)] - conj(in[i]);
	fft(out);
	for(int i = 0; i < (int)res.size(); ++i) res[i] = imag(out[i]) / (4 * n);
	return res;
}

int sol[1000100] = {0};

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, x, y, q, broj;
	cin >> n >> x >> y;
	n++;
	vector <double> a(x + 1, 0), b(x + 1, 0);
	REP(i, n) {
		cin >> broj;
		a[broj] = 1;
		b[x - broj] = 1;
	}
	a = mult_pol(a, b);
	for(int i = x + 1; i < (int)a.size(); i++) {
		if(a[i] > 0.5) {
			for(int j = (i - x) * 2 + y * 2; j < 1000010; j += (i - x) * 2 + y * 2) sol[j] = (i - x) * 2 + y * 2;
		}
	}
	cin >> q;
	REP(qq, q) {
		cin >> n;
		if(sol[n]) cout << sol[n] << " ";
		else cout << -1 << " ";
	}
	cout << endl;
	return 0;
}


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

#define REP(i, n) for(int i = 0; i < (n); i++)

typedef complex<double> C;
void fft(vector <C> &a) {
	int n = a.size(), L = 31 - __builtin_clz(n);
	static vector <complex <double> > R(2, 1);
	static vector <C> rt(2, 1);  // (^ 10% faster if double)
	for(static int k = 2; k < n; k *= 2) {
		R.resize(n); rt.resize(n);
		auto x = polar(1.0, acos(-1.0) / k);
		for(int i = k; i < 2 * k; ++i) rt[i] = R[i] = i & 1 ? R[i/2] * x : R[i/2];
	}
	vector <int> rev(n);
	for(int i = 0; i < n; ++i) rev[i] = (rev[i / 2] | (i & 1) << L) / 2;
	for(int i = 0; i < n; ++i) if(i < rev[i]) swap(a[i], a[rev[i]]);
	for(int k = 1; k < n; k *= 2)
		for(int i = 0; i < n; i += 2 * k) for(int j = 0; j < k; ++j) {
			 C z = rt[j+k] * a[i+j+k]; // (25% faster if hand-rolled)  /// include-line
			//auto x = (double *)&rt[j+k], y = (double *)&a[i+j+k];        /// exclude-line
			//C z(x[0]*y[0] - x[1]*y[1], x[0]*y[1] + x[1]*y[0]);           /// exclude-line
			a[i + j + k] = a[i + j] - z;
			a[i + j] += z;
		}
}
vector <double> mult_pol(const vector <double> &a, const vector <double> &b) {
	if (a.empty() || b.empty()) return {};
	vector <double> res(a.size() + b.size() - 1);
	int L = 32 - __builtin_clz(res.size()), n = 1 << L;
	vector<C> in(n), out(n);
	copy(begin(a), end(a), begin(in));
	for(int i = 0; i < (int)b.size(); ++i) in[i].imag(b[i]);
	fft(in);
	for(C& x : in) x *= x;
	for(int i=0;i<n;++i) out[i] = in[-i & (n - 1)] - conj(in[i]);
	fft(out);
	for(int i = 0; i < (int)res.size(); ++i) res[i] = imag(out[i]) / (4 * n);
	return res;
}

int sol[1000100] = {0};

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, x, y, q, broj;
	cin >> n >> x >> y;
	n++;
	vector <double> a(x + 1, 0), b(x + 1, 0);
	REP(i, n) {
		cin >> broj;
		a[broj] = 1;
		b[x - broj] = 1;
	}
	a = mult_pol(a, b);
	for(int i = x + 1; i < (int)a.size(); i++) {
		if(a[i] > 0.5) {
			for(int j = (i - x) * 2 + y * 2; j < 1000010; j += (i - x) * 2 + y * 2) sol[j] = (i - x) * 2 + y * 2;
		}
	}
	cin >> q;
	REP(qq, q) {
		cin >> n;
		if(sol[n]) cout << sol[n] << " ";
		else cout << -1 << " ";
	}
	cout << endl;
	return 0;
}


#include<iostream>
#include <bits/stdc++.h>
#define ll long long
#define ld  double
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
using cd = complex<double>;
const double PI = acos(-1);
void fft(vector<cd> & a, bool invert)
{
    int n = a.size();

    for (int i = 1, j = 0; i < n; i++)
    {
        int bit = n >> 1;
        for (; j & bit; bit >>= 1)
            j ^= bit;
        j ^= bit;

        if (i < j)
            swap(a[i], a[j]);
    }

    for (int len = 2; len <= n; len <<= 1)
    {
        double ang = 2 * PI / len * (invert ? -1 : 1);
        cd wlen(cos(ang), sin(ang));
        for (int i = 0; i < n; i += len)
        {
            cd w(1);
            for (int j = 0; j < len / 2; j++)
            {
                cd u = a[i+j], v = a[i+j+len/2] * w;
                a[i+j] = u + v;
                a[i+j+len/2] = u - v;
                w *= wlen;
            }
        }
    }

    if (invert)
    {
        for (cd & x : a)
            x /= n;
    }
}
vector<int> multiply(vector<int> &a, vector<int> &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,0);
    fft(fb,0);

    for(int i=0; i<n; i++)
        fa[i]*=fb[i];
    fft(fa,1);
    vector<int> res(n);
    for(int i=0; i<n; i++)
        res[i]=round(fa[i].real());
    return res;
}
int n, x, y, q;
vector<int> v1, v2;
bool good[1000009];
int main()
{
    IO
    cin>>n>>x>>y;
    v1.resize(x+1,0);
    v2.resize(x+1,0);
    n++;
    while(n--)
    {
        int a;
        cin>>a;
        v1[a]++;
        v2[-a+x]++;
    }
    vector<int> res=multiply(v1,v2);

    for(int i=1; i<=x; i++)
        if(res[i+x])
            good[i*2+2*y]=true;
    cin>>q;
    while(q--)
    {
        int l ;
        cin>>l;
        if(l>8e5)
            cout<<"-1 ";
        else
        {
            int ans=-1;
            for(int i=1; i*i<=l; i++)
            {
                if(l%i)
                    continue;
                if(good[l/i])
                    ans=max(ans,l/i);
                if(good[i])
                    ans=max(ans,i);
            }
            cout<<ans<<" ";
        }
    }
}


#include<iostream>
#include <bits/stdc++.h>
#define ll long long
#define ld  double
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
using cd = complex<double>;
const double PI = acos(-1);
void fft(vector<cd> & a, bool invert)
{
    int n = a.size();

    for (int i = 1, j = 0; i < n; i++)
    {
        int bit = n >> 1;
        for (; j & bit; bit >>= 1)
            j ^= bit;
        j ^= bit;

        if (i < j)
            swap(a[i], a[j]);
    }

    for (int len = 2; len <= n; len <<= 1)
    {
        double ang = 2 * PI / len * (invert ? -1 : 1);
        cd wlen(cos(ang), sin(ang));
        for (int i = 0; i < n; i += len)
        {
            cd w(1);
            for (int j = 0; j < len / 2; j++)
            {
                cd u = a[i+j], v = a[i+j+len/2] * w;
                a[i+j] = u + v;
                a[i+j+len/2] = u - v;
                w *= wlen;
            }
        }
    }

    if (invert)
    {
        for (cd & x : a)
            x /= n;
    }
}
vector<int> multiply(vector<int> &a, vector<int> &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,0);
    fft(fb,0);

    for(int i=0; i<n; i++)
        fa[i]*=fb[i];
    fft(fa,1);
    vector<int> res(n);
    for(int i=0; i<n; i++)
        res[i]=round(fa[i].real());
    return res;
}
int n, x, y, q;
vector<int> v1, v2;
bool good[1000009];
int main()
{
    IO
    cin>>n>>x>>y;
    v1.resize(x+1,0);
    v2.resize(x+1,0);
    n++;
    while(n--)
    {
        int a;
        cin>>a;
        v1[a]++;
        v2[-a+x]++;
    }
    vector<int> res=multiply(v1,v2);

    for(int i=1; i<=x; i++)
        if(res[i+x])
            good[i*2+2*y]=true;
    cin>>q;
    while(q--)
    {
        int l ;
        cin>>l;

            int ans=-1;
            for(int i=1; i*i<=l; i++)
            {
                if(l%i)
                    continue;
                if(good[l/i])
                    ans=max(ans,l/i);
                if(good[i])
                    ans=max(ans,i);
            }
            cout<<ans<<" ";
    }
}


#include<iostream>
#include <bits/stdc++.h>
#define ll long long
#define ld  double
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
using cd = complex<double>;
const double PI = acos(-1);
void fft(vector<cd> & a, bool invert)
{
    int n = a.size();

    for (int i = 1, j = 0; i < n; i++)
    {
        int bit = n >> 1;
        for (; j & bit; bit >>= 1)
            j ^= bit;
        j ^= bit;

        if (i < j)
            swap(a[i], a[j]);
    }

    for (int len = 2; len <= n; len <<= 1)
    {
        double ang = 2 * PI / len * (invert ? -1 : 1);
        cd wlen(cos(ang), sin(ang));
        for (int i = 0; i < n; i += len)
        {
            cd w(1);
            for (int j = 0; j < len / 2; j++)
            {
                cd u = a[i+j], v = a[i+j+len/2] * w;
                a[i+j] = u + v;
                a[i+j+len/2] = u - v;
                w *= wlen;
            }
        }
    }

    if (invert)
    {
        for (cd & x : a)
            x /= n;
    }
}
vector<int> multiply(vector<int> &a, vector<int> &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,0);
    fft(fb,0);

    for(int i=0; i<n; i++)
        fa[i]*=fb[i];
    fft(fa,1);
    vector<int> res(n);
    for(int i=0; i<n; i++)
        res[i]=round(fa[i].real());
    return res;
}
int n, x, y, q;
vector<int> v1, v2;
bool good[1000009];
int main()
{
    IO
    cin>>n>>x>>y;
    v1.resize(x+1,0);
    v2.resize(x+1,0);
    n++;
    while(n--)
    {
        int a;
        cin>>a;
        v1[a]++;
        v2[-a+x]++;
    }
    vector<int> res=multiply(v1,v2);

    for(int i=1; i<=x; i++)
            if(res[i+x])
                good[i*2+2*y]=true;
    cin>>q;
    while(q--)
    {
        int l ;
        cin>>l;
        if(l>8e5)
            cout<<"-1 ";
        else
        {
            int ans=-1;
            for(int i=1; i*i<=l; i++)
            {
                if(good[l/i])
                    ans=max(ans,l/i);
                if(good[i])
                    ans=max(ans,i);
            }
            cout<<ans<<" ";
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<vvc> vvvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<pi> vpi;
typedef vector<vpi> vvpi;
typedef vector<vvpi> vvvpi;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef complex<double> cd;
typedef vector<cd> vcd;

typedef unsigned int uint;

template<class C> void mini(C&a, C b){ a=min(a, b);}
template<class C> void maxi(C&a, C b){a=max(a,b);}
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define forall(it,s) for(auto it = s.begin(); it != s.end(); ++it)
#define F0(i,n) for(int i = 0; i < n; i++)
#define F1(i,n) for(int (i) = 1; i <= n; i++)
#define F0R(i,n) for(int (i) = n-1; i >= 0; i--)
#define F1R(i,n) for(int (i) = n; i >= 1; i--)
#define REP(i,a,b) for(int i = a; i <= b; i++)
#define REPR(i,a,b) for(int i = a; i >= b; i--)
#define INF 1e9
#define todo(v) v.begin(),v.end()
#define eps 0.000000000001
#define mod 1000000007

const double PI = acos(-1);

void fft(vcd& a, bool invert){
    int n = a.size();
    for(int i = 1, j = 0; i < n; i++){
        int bit = n >> 1;
        for(; j & bit; bit >>= 1)
            j ^= bit;
        j ^= bit;

        if(i < j)
            swap(a[i], a[j]);
    }

    for(int len = 2; len <= n; len <<= 1){
        double ang = 2*PI/len*(invert ? -1 : 1);
        cd wlen(cos(ang), sin(ang));
        for(int i = 0; i < n; i+=len){
            cd w(1);
            for(int j = 0; j < len/2; j++){
                cd u = a[i+j], v = a[i+j+len/2]*w;
                a[i+j] = u+v;
                a[i+j+len/2] = u-v;
                w *= wlen;
            }
        }
    }

    if(invert){
        for(cd & x : a)
            x /= n;
    }
}

//multiplica dos polinomios usando fft en O(nlogn)
vi multiply(vi const& a, vi const& b){
    vcd 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);

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

void a(){
    int n,x,y;
    cin>>n>>x>>y;
    vi a(400001);
    vi b(400001);
    int aux;
    F0(i,n+1){
        cin>>aux;
        a[aux]++;
        b[200000 - aux]++;
    }

    a = multiply(a,b);

    vi res(500001,-1);
    REP(d,2,500000){
        int i = d-y+200000;
        if(i <= 200000 or i >= a.size() or a[i] == 0) continue;
        int j = d;
        while(j < res.size()){
            res[j] = 2*d;
            j += d;
        }
    }
    int q;
    cin>>q;
    int l;
    while(q--){
        cin>>l;
        l /= 2;
        cout<<res[l]<<' ';
    }
    cout<<'\n';
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    a();
    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cassert>
#include<queue>
#include<vector>
#include<map>
#include<cmath>
#include<set>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
const int N=800010;
int k,pos[N];
namespace FFT{
	struct comp{
	long double r,i;comp(long double _r=0,long double _i=0){r=_r;i=_i;}
	comp operator+(const comp x){return comp(r+x.r,i+x.i);}
	comp operator-(const comp x){return comp(r-x.r,i-x.i);}
	comp operator*(const comp x){return comp(r*x.r-i*x.i,r*x.i+i*x.r);}
	comp conj(){return comp(r,-i);}
	}A[N],B[N];
	const long double pi=acos(-1.0);
	void FFT(comp a[],int n,int t){
		for(int i=1;i<n;i++)if(i<pos[i])swap(a[i],a[pos[i]]);
		for(int d=0;(1<<d)<n;d++){
		  int m=1<<d,m2=m<<1;
		  long double o=pi*2/m2*t;comp _w(cos(o),sin(o));
		  for(int i=0;i<n;i+=m2){
		    comp w(1,0);
		    for(int j=0;j<m;j++){
		      comp&A=a[i+j+m],&B=a[i+j],t=w*A;
		      A=B-t;B=B+t;w=w*_w;
		    }
		  }
		}
		if(t==-1)for(int i=0;i<n;i++)a[i].r/=n;
	}
	void mul(int*a,int*b,int*c){
		int i,j;
		for(i=0;i<k;i++)A[i]=comp(a[i],b[i]);
		FFT(A,k,1);
		for(i=0;i<k;i++){
			j=(k-i)&(k-1);
			B[i]=(A[i]*A[i]-(A[j]*A[j]).conj())*comp(0,-0.25);
		}
		FFT(B,k,-1);
		for(i=0;i<k;i++)c[i]=(long long)(B[i].r+0.5);
	}
}
int a[N],b[N],c[N],n,X,Y,q;
int main()
{
	scanf("%d%d%d",&n,&X,&Y);
	rep(i,n+1){int x;scanf("%d",&x);a[x]=1;b[X-x]=1;}
	for(k=1;k<X;k<<=1);k<<=1;
	int j=__builtin_ctz(k)-1;
	for(int i=0;i<k;i++)pos[i]=pos[i>>1]>>1|((i&1)<<j);
	FFT::mul(a,b,c);
	scanf("%d",&q);
	rep(i,q)
	{
		int x;
		scanf("%d",&x);
		int top=(int)sqrt(x),ans=-1;
		rep(j,top)
		if(x%j==0)
		{
			int now=x/j-2*Y;
			if(now<=0)break;
			if(!(now&1)&&c[now/2+X]){ans=x/j;break;}
			now=j-2*Y;
			if(now>0&&!(now&1)&&c[now/2+X])ans=j;
		}
		printf("%d%c",ans," \n"[i==q]);
	}
	return 0;
}


/*
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int maxn = 200005;
const int maxm = 50005;
const int maxk = 555;
const ll mod = 1000000007;

struct Linearbasis {
    ll p[70],b[70];
    int cnt;
    //有些题会默认空集属于线性空间，有些不会，所以需要flag来判断是否有0
    bool flag;

    void init() {
        memset(p,0,sizeof(p));
        memset(b,0,sizeof(b));
        cnt = 0;
        flag = false;//判断s集合有没有满秩
    }

    bool Insert (ll x) { // 插入后化为上三角矩阵
        for(int i=63;i>=0;i--) {
            if((x>>i) & 1) {
                if(!p[i]) {
                    p[i] = x;
                    break;
                }
                x^=p[i];
            }
        }
        if(x>0) cnt++;
        else flag = true;//有0
        return x > 0;
    }

    ll check(ll x) {
        for(int i=63;i>=0;i--) {
            if((x>>i) &1) {
                x^=p[i];
            }
        }
        return x;
    }

    Linearbasis operator +(const Linearbasis &r) const {//线性基合并
        Linearbasis res=r;
        for(int i=0;i<=62;i++) {
            if(p[i])
                res.Insert(p[i]);
        }
        return res;
    }

    ll querymax (ll x = 0) { // 求x能与线性基的异或最大，x=0表示max{span(s)}
        ll res=x;
        for(int i=63;i>=0;i--) {
            if((res^p[i])>res) res^=p[i];
        }
        return res;
    }

    ll querymin() {
        for(int i=0;i<=63;i++) {
            if(p[i]) return p[i];
        }
        return 0;
    }

    void rebuild() {  //化为对角矩阵
        for(int i=63;i>=0;i--) {
            for(int j=i-1;j>=0;j--) {
                if((p[i]>>j)&1) p[i]^=p[j];
            }
        }
        cnt = 0;
        for(int i=0;i<=63;i++) {
            if(p[i]) b[cnt++] = p[i];
        }
    }

    ll kthmin(ll k) { // 求第k小必须化为对角矩阵
        if(flag) k--;//有的话意味着最小可以为0
        ll res=0;
        if(!k) return 0;
        if(k>=(1ll<<cnt)) return -1;
        for(int i=63;i>=0;i--) {
            if((k>>i)&1) res^=b[i];
        }
        return res;
    }
};

Linearbasis sol;

int main() {
    int T,ca=1;scanf("%d",&T);
    while(T--) {
        sol.init();
        int n,m;scanf("%d%d",&n,&m);
        for(int i=1;i<=m;i++) {
            int k;scanf("%d",&k);
            ll tmp=0;
            for(int i=1;i<=k;i++) {
                ll x;scanf("%lld",&x);
                tmp|=(1ll<<(x));
            }
            sol.Insert(tmp);
        }
        int q;scanf("%d",&q);
        printf("Case %d:\n",ca++);
        while(q--) {

            ll tmp=0;
            for(int i=1;i<=n;i++) {
                int x;scanf("%d",&x);
                if(x>0) tmp|=(1ll<<((ll)i));
            }
            //printf("fff = %d\n",m-sol.cnt);
            if(sol.check(tmp)==0) printf("%lld\n",1ll<<((ll)(m-sol.cnt)));
            else printf("0\n");
        }
    }
    return 0;
}
*/
#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;
}