#include #define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++) using namespace std; typedef long long ll; const double pi = acos(-1); vector> fft(vector> f, int n, int sign) { if(n == 1) return f; vector> f0(n / 2), f1(n / 2); for(int i = 0; i < n / 2; i++) { f0[i] = f[i * 2]; f1[i] = f[i * 2 + 1]; } vector> ft0 = fft(f0, n / 2, sign); vector> ft1 = fft(f1, n / 2, sign); vector> ft(n); complex zeta(cos(2 * pi / n), sign * sin(2 * pi / n)); complex x = 1; for(int i = 0; i < n / 2; i++) { ft[i] = ft0[i] + x * ft1[i]; x *= zeta; } for(int i = 0; i < n / 2; i++) { ft[n / 2 + i] = ft0[i] + x * ft1[i]; x *= zeta; } return ft; } vector> dft(vector> f) { int n = f.size(); vector> ft = fft(f, n, 1); return ft; } vector> idft(vector> ft) { int n = ft.size(); vector> f = fft(ft, n, -1); for(int i = 0; i < n; i++) f[i] /= n; return f; } vector convolution(vector a, vector b) { ll p = a.size(), q = b.size(); ll n = 1; while(n < p + q + 1) n *= 2; vector> g(n), h(n); for(int i = 0; i < p; i++) g[i] = a[i]; for(int i = 0; i < q; i++) h[i] = b[i]; vector> gt = dft(g); vector> ht = dft(h); vector> ft(n); for(int i = 0; i < n; i++) ft[i] = gt[i] * ht[i]; vector> f = idft(ft); vector c(n); for(int i = 0; i < n; i++) c[i] = f[i].real(); return c; } int main(void) { ll L, M, N; cin >> L >> M >> N; vector A(N + 1), B(N + 1); REP(i, 0, L) { ll a; cin >> a; A[a] = 1; } REP(i, 0, M) { ll b; cin >> b; B[N - b] = 1; } ll Q; cin >> Q; vector ans = convolution(A, B); REP(i, 0, Q) cout << (ll) (ans[N + i] + 0.5) << endl; }