#include using namespace std; #define DEBUG(x) cerr<<#x<<": "< #define vl vector #define vii vector< vector > #define vll vector< vector > #define vs vector #define pii pair #define pis pair #define psi pair #define pll pair template pair operator+(const pair &s, const pair &t) { return pair(s.first + t.first, s.second + t.second); } template pair operator-(const pair &s, const pair &t) { return pair(s.first - t.first, s.second - t.second); } template ostream& operator<<(ostream& os, pair p) { os << "(" << p.first << ", " << p.second << ")"; return os; } #define X first #define Y second #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep1(i,n) for(int i=1;i<=(int)(n);i++) #define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--) #define rrep1(i,n) for(int i=(int)(n);i>0;i--) #define REP(i,a,b) for(int i=a;i bool chmax(T &a, const T &b) { if (a bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; } #define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end()); const ll inf = 1000000001; const ll INF = (ll)1e18 + 1; const long double pi = 3.1415926535897932384626433832795028841971L; #define Sp(p) cout<> k >> n >> m; vl a(k), c(k + 1, -1); rep (i, k) cin >> a[i]; rep1 (i, k) cin >> c[i]; for (int i = k; i < n; i++) { a.push_back(0); for (int j = 1; j <= k; j++) { a[i] += c[j] * a[i - j]; a[i] %= MOD; } } for (int i = 0; i < n; i++) { dp[i][0] = c[0] * a[i]; for (int j = 1; j <= k; j++) { if (i - j < 0) break; dp[i][j] = (dp[i][j - 1] + c[j] * a[i - j]) % MOD; } } // rep (i, n) { // rep (j, k + 1) { // cout << dp[i][j] << " "; // } // cout << endl; // } // DEBUG_VEC(a); vl y(n); while (m--) { int l, r; cin >> l >> r; for (int i = l; i < min(l + k, n); i++) { y[i] += dp[i - l][i - l]; y[i] %= MOD; } // vl x(n); // x[0] = c[0] * y[0]; // for (int i = 1; i < n; i++) { // for (int j = 1; j <= min(k, i); j++) { // x[i] += c[j] * x[i - j]; // } // x[i] -= y[i]; // } // DEBUG_VEC(x); for (int i = r; i < min(r + k, n); i++) { y[i] -= dp[i - l][i - r]; y[i] %= MOD; } // DEBUG_VEC(y); // // vl x(n); // fill(all(x), 0); // x[0] = c[0] * y[0]; // for (int i = 1; i < n; i++) { // for (int j = 1; j <= min(k, i); j++) { // x[i] += c[j] * x[i - j]; // } // x[i] -= y[i]; // } // DEBUG_VEC(x); } vl x(n); x[0] = c[0] * y[0]; for (int i = 1; i < n; i++) { for (int j = 1; j <= min(k, i); j++) { x[i] += c[j] * x[i - j]; } x[i] -= y[i]; x[i] %= MOD; } rep (i, n) { cout << (x[i] + MOD) % MOD << endl; } }