#pragma GCC target("avx2") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include using namespace std; const long long MOD = 1000000007; int main(){ int K, N, M; cin >> K >> N >> M; vector a(N + 1, 0); for (int i = 0; i < K; i++){ cin >> a[i]; } vector c(K); for (int i = 0; i < K; i++){ cin >> c[i]; } for (int i = K; i <= N; i++){ for (int j = 0; j < K; j++){ a[i] += a[i - j - 1] * c[j] % MOD; a[i] %= MOD; } } vector b(K); for (int i = 0; i < K; i++){ b[i] = a[i]; for (int j = 0; j < i; j++){ b[i] -= a[i - j - 1] * c[j] % MOD; b[i] += MOD; } b[i] %= MOD; } vector> prod(N + 1, vector(K)); for (int i = 0; i <= N; i++){ for (int j = 0; j < K; j++){ prod[i][j] = a[i] * c[j] % MOD; } } vector> query(M); for (int i = 0; i < M; i++){ int l, r; cin >> l >> r; query[i] = make_tuple(r - l, l, r); } sort(query.begin(), query.end()); vector x(N, 0); vector y(N + K, 0); vector sub(K, 0); int prev = -1; for (int i = 0; i < M; i++){ int l = get<1>(query[i]); int r = get<2>(query[i]); if (r <= l + max(K * K, 100)){ for (int j = l; j < r; j++){ x[j] += a[j - l]; x[j] %= MOD; } } else { for (int j = l; j < l + K; j++){ y[j] += b[j - l]; } if (prev != r - l){ sub[0] = a[r - l]; for (int j = 1; j < K; j++){ sub[j] = 0; for (int k = j; k < K; k++){ sub[j] += prod[r - l - 1 + j - k][k]; } sub[j] %= MOD; } prev = r - l; } for (int j = r; j < r + K; j++){ y[j] += MOD - sub[j - r]; } } } for (int i = 0; i < N + K; i++){ y[i] %= MOD; } for (int i = 0; i < N + K; i++){ for (int j = 0; j < min(K, i); j++){ y[i] += y[i - j - 1] * c[j] % MOD; y[i] %= MOD; } } for (int i = 0; i < N; i++){ cout << (x[i] + y[i]) % MOD << endl; } }