#include using namespace std; using ll = long long; #define rep2(i, m, n) for(int i=int(m); i= MOD || xx <= -MOD) x = xx % MOD; if (x < 0) x += MOD; } mint operator-() const { return mint(-x);} mint& operator+=(const mint a) { if ((x += a.x) >= MOD) x -= MOD; return *this; } mint& operator-=(const mint a) { if ((x -= a.x) < 0) x += MOD; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;} mint operator+(const mint a) const { return mint(*this) += a;} mint operator-(const mint a) const { return mint(*this) -= a;} mint operator*(const mint a) const { return mint(*this) *= a;} }; istream& operator>>(istream& is, mint& a) { return is >> a.x;} ostream& operator<<(ostream& os, const mint& a) { return os << a.x;} using Vm = vector; int main() { int k, n, m; cin >> k >> n >> m; Vm a(k+n), c(k+1); c[0] = -1; rep(i, k) cin >> a[i]; rep(i, k) cin >> c[i+1]; rep2(i, k, n+k) rep2(j, 1, k+1) a[i] += c[j]*a[i-j]; Vm y(n); rep(_, m) { int l, r; cin >> l >> r; rep(i, k) rep(j, min(k, n-l)-i) y[l+i+j] -= c[i] * a[j]; rep(i, k) rep(j, min(k, n-r)-i) y[r+i+j] += c[i] * a[r-l+j]; } Vm x(n+k); rep(i, n) { x[k+i] = y[i]; rep2(j, 1, k+1) x[k+i] += c[j] * x[k+i-j]; cout << x[k+i] << "\n"; } return 0; }