Problem: A lottery is being held in a corner of the venue of the Aizu festival. Several types of balls are inside the lottery box and each type has its unique integer printed on the surfaces of the balls. An integer T is printed on the lottery box.

In the lottery, you first declare two integers A and B, and draw up to M balls from the box. Let the sum of the integers printed on the balls be S. You can get a wonderful gift if the following two criteria are met: S divided by T gives a remainder greater than or equal to A, and S divided by T gives a quotient (fractional portion dropped) greater than or equal to B.

Write a program to determine if you have any chance of getting the gift given the following information: the number of ball types, ball-type specific integers, the maximum number of balls to be drawn from the box, the integer printed on the lottery box, and two integers declared before drawing. Assume that each ball type has sufficient (≥M) population in the box. Note also that there may be a chance of getting the gift even without drawing any ball.



Input

The input is given in the following format.


N M T
a_1
a_2
:
a_N
Q
A_1 B_1
A_2 B_2
:
A_Q B_Q


The first line provides the number of ball types N(1≤N≤105), the maximum number of balls you can draw from the box M(1≤M≤105), and the integer printed on the box T(1≤T≤1000). Each of the subsequent N lines provides an integer a_i (1≤a_i≤109) printed on the i-th ball type. The next line following these provides the number of declarations Q (1≤Q≤105). Each of the Q lines following this provides a pair of integers A_i (0 ≤ A_i < T), B_i (0 ≤ B_i ≤ 109) that constitute the i-th declaration.

Output

Output a line for each pair of declaration A and B that contains "yes" if there is a chance of getting the gift or "no" otherwise.

Example

Input

3 2 7
8
3
6
5
2 2
3 2
4 1
6 1
6 0


Output

yes
no
yes
no
yes

Solution (in CPP):

Solution:
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld =long double;
const ld eps = 1e-9;

#define Seg_Max_N (1<<18) 

using Value = int;
const Value ini = 0;
struct segtree {
	int N;
	vector<Value>dat;

	segtree() {}
	segtree(int n) :dat(2 * Seg_Max_N) {
		N = 1;
		while (N < n) N *= 2;
		for (int i = 0; i < 2 * N - 1; i++) {
			dat[i] = ini;
		}
	}
	Value connect(const Value&l, const Value&r) {
		return l+r;
	}
	// update k th element
	void update(int k, Value a) {
		k += N - 1;
		dat[k] = a;

		while (k > 0) {
			k = (k - 1) / 2;
			const Value al(dat[k * 2 + 1]);
			const Value ar(dat[k * 2 + 2]);
			dat[k] = connect(al, ar);
		}
	}
	// min [a, b)
	Value  query(int a, int b) { return query(a, b, 0, 0, N); }
	Value  query(int a, int b, int k, int l, int r) {
		if (r <= a or b <= l) return ini;
		if (a <= l and r <= b) return dat[k];
		const int m = (l + r) / 2;
		const Value al(query(a, b, k * 2 + 1, l, m));
		const Value ar(query(a, b, k * 2 + 2, m, r));
		return connect(al, ar);
	}
};
int main()
{
	int N,M,T;cin>>N>>M>>T;
	vector<vector<long long int>>dp(20,vector<long long int>(T,-1e9));

	dp[0][0]=0;
	for (int i = 0; i < N; ++i) {
		int a;cin>>a;
		dp[0][a%T]=max(a/T,int(dp[0][a%T]));
	}

	for (int i = 0; i < 19; ++i) {
		for (int x = 0; x < T; ++x) {
			for (int y = 0; y < T; ++y) {
				if (dp[i][x] >= 0 && dp[i][y] >= 0) {
					dp[i+1][(x+y)%T]=max(dp[i+1][(x+y)%T],dp[i][x]+dp[i][y]+(x+y>=T));
				}
			}
		}
	}
	bitset<20>bs(M);
	vector<long long int>ndp(T, -1e9);
	{
		ndp[0]=0;
		for (int i = 0; i < 20; ++i) {
			if (bs[i]) {
				auto next_dp(ndp);
				for (int x = 0; x < T; ++x) {
					for (int y = 0; y < T; ++y) {
						if (ndp[x] >= 0 && dp[i][y] >= 0) {
							next_dp[(x + y) % T] = max(next_dp[(x + y) % T], ndp[x]+ dp[i][y] + (x + y >= T));
						}
					}
				}
				ndp=next_dp;
			}
		}
	}
	for (int i = 0; i < T - 1; ++i) {
		ndp[T-i-2]=max(ndp[T-i-2],ndp[T-i-1]);
	}
	int Q;cin>>Q;
	while (Q--) {
		int A,B;cin>>A>>B;
		bool ok=ndp[A]>=B;
		if(ok)cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
	return 0;
}