#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]); } int s, t; for(int i = 1; i < N; i <<= 1) { for(int j = 0; j < N; j += i * 2) { for(int k = 0; k < i; k++) { 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(vector< int > A, vector< int > B) { int sz = 1, last = A.size() + B.size() - 1; while(sz < last) sz <<= 1; A.resize(sz); B.resize(sz); DiscreteFourierTransform(A, false); DiscreteFourierTransform(B, false); for(int i = 0; i < sz; i++) A[i] = mul(A[i], B[i]); DiscreteFourierTransform(A, true); A.resize(last); return A; } }; 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]); }