#include using namespace std; using int64 = long long; namespace FastFourierTransform { using C = complex< double >; void DiscreteFourierTransform(vector< C > &F, bool rev) { const int N = (int) F.size(); const double PI = (rev ? -1 : 1) * acos(-1); 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]); } C wr, w, s, t; for(int i = 1; i < N; i <<= 1) { wr = polar(1.0, PI / i); for(int j = 0; j < N; j += i * 2) { w = 1.0; for(int k = 0; k < i; k++) { s = F[j + k]; t = C(F[j + k + i].real() * w.real() - F[j + k + i].imag() * w.imag(), F[j + k + i].real() * w.imag() + F[j + k + i].imag() * w.real()); F[j + k] = s + t, F[j + k + i] = s - t; w *= wr; } } } if(rev) { double temp = 1.0 / N; for(int i = 0; i < N; i++) F[i] *= temp; } } vector< int64 > Multiply(const vector< int64 > &A, const vector< int64 > &B) { int sz = 1; while(sz < A.size() + B.size() - 1) sz <<= 1; vector< C > 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] *= G[i]; DiscreteFourierTransform(F, true); vector< int64 > X(A.size() + B.size() - 1); for(int i = 0; i < A.size() + B.size() - 1; i++) X[i] = F[i].real() + 0.5; return (X); } }; int main() { int N, M, P; scanf("%d %d %d", &N, &M, &P); vector< int64 > 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)); auto C = FastFourierTransform::Multiply(A, B); int Q; scanf("%d", &Q); for(int i = 0; i < Q; i++) printf("%lld\n", C[P + i - 1]); }