#include using namespace std; #define getchar getchar_unlocked struct NumberTheoreticTransform { int mod; int root; NumberTheoreticTransform(int mod, int root) : mod(mod), root(root) {} int mul(int x, int y) { return int64_t(x) * y % mod; } int add(int x, int y) { return (x += y) >= mod ? x - mod : x; } int pow(int x, int y) { int res = 1; while (y > 0) { if (y & 1) res = mul(res, x); x = mul(x, x); y >>= 1; } return res; } int inv(int x) { return pow(x, mod - 2); } void ntt(std::vector &a, bool rev = false) { int n = a.size(); int h = 0; for (int i = 0; 1 << i < n; i++) h++; for (int i = 0; i < n; i++) { int j = 0; for (int k = 0; k < h; k++) j |= (i >> k & 1) << (h - 1 - k); if (i < j) std::swap(a[i], a[j]); } for (int i = 1; i < n; i *= 2) { int w = pow(root, (mod - 1) / (i * 2)); if (rev) w = inv(w); for (int j = 0; j < n; j += i * 2) { int wn = 1; for (int k = 0; k < i; k++) { int s = a[j + k + 0]; int t = mul(a[j + k + i], wn); a[j + k + 0] = add(s, t); a[j + k + i] = add(s, mod - t); wn = mul(wn, w); } } } int v = inv(n); if (rev) for (int i = 0; i < n; i++) a[i] = mul(a[i], v); } std::vector mul(std::vector a, std::vector b) { int s = a.size() + b.size() - 1; int t = 1; while (t < s) t *= 2; a.resize(t); b.resize(t); ntt(a); ntt(b); for (int i = 0; i < t; i++) { a[i] = mul(a[i], b[i]); } ntt(a, true); a.resize(s); return a; } }; int in() { char c; while ((c = getchar()) < '0') if (c == EOF) return -1; int n = c - '0'; while ((c = getchar()) >= '0') n = n * 10 + (c - '0'); return n; } int main() { int L = in(), M = in(), N = in(); const int X = 1 << 17; vector a(X), b(X); for (int i = 0; i < L; i++) a[in()] = 1; for (int i = 0; i < M; i++) b[N - in()] = 1; NumberTheoreticTransform ntt(1012924417, 5); a = ntt.mul(a, b); int Q = in(); for (int i = 0; i < Q; i++) { printf("%d\n", a[N + i]); } }