#include using namespace std; template< int mod, int primitiveroot > struct NumberTheoreticTransform { vector< vector< int > > rts, rrts; void ensure_base(int N) { if(rts.size() >= N) return; rts.resize(N), rrts.resize(N); for(int i = 1; i < N; i <<= 1) { if(rts[i].size()) continue; int w = mod_pow(primitiveroot, (mod - 1) / (i * 2)); int rw = inverse(w); rts[i].resize(i), rrts[i].resize(i); rts[i][0] = 1, rrts[i][0] = 1; for(int k = 1; k < i; k++) { rts[i][k] = mul(rts[i][k - 1], w); rrts[i][k] = mul(rrts[i][k - 1], rw); } } } inline int mod_pow(int x, int n) { int ret = 1; while(n > 0) { if(n & 1) ret = mul(ret, x); x = mul(x, x); n >>= 1; } return ret; } inline int inverse(int x) { return mod_pow(x, mod - 2); } inline int add(int x, int y) { x += y; if(x >= mod) x -= mod; return x; } inline int mul(int a, int b) { return int(1LL * a * b % mod); } void DiscreteFourierTransform(vector< int > &F, bool rev) { const int N = (int) F.size(); ensure_base(N); for(int i = 0, j = 1; j + 1 < N; j++) { for(int k = N >> 1; k > (i ^= k); k >>= 1); if(i > j) swap(F[i], F[j]); } for(int i = 1; i < N; i <<= 1) { for(int j = 0; j < N; j += i * 2) { for(int k = 0; k < i; k++) { int s = F[j + k], t = mul(F[j + k + i], rev ? rrts[i][k] : rts[i][k]); F[j + k] = add(s, t), F[j + k + i] = add(s, mod - t); } } } if(rev) { int temp = inverse(N); for(int i = 0; i < N; i++) F[i] = mul(F[i], temp); } } vector< int > Multiply(const vector< int > &A, const vector< int > &B) { int sz = 1; while(sz < A.size() + B.size() - 1) sz <<= 1; vector< int > F(sz), G(sz); for(int i = 0; i < A.size(); i++) F[i] = A[i]; for(int i = 0; i < B.size(); i++) G[i] = B[i]; DiscreteFourierTransform(F, false); DiscreteFourierTransform(G, false); for(int i = 0; i < sz; i++) F[i] = mul(F[i], G[i]); DiscreteFourierTransform(F, true); F.resize(A.size() + B.size() - 1); return F; } }; int main() { int N, M, P; scanf("%d %d %d", &N, &M, &P); vector< int > A(P), B(P); for(int i = 0; i < N; i++) { int x; scanf("%d", &x); A[x - 1] = 1; } for(int i = 0; i < M; i++) { int x; scanf("%d", &x); B[x - 1] = 1; } reverse(begin(B), end(B)); NumberTheoreticTransform< 1012924417, 5 > ntt; auto C = ntt.Multiply(A, B); int Q; scanf("%d", &Q); for(int i = 0; i < Q; i++) printf("%d\n", C[P + i - 1]); }