#include using namespace std; using Int = long long; const char newl = '\n'; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a void drop(const T &x){cout< vector read(size_t n){ vector ts(n); for(size_t i=0;i>ts[i]; return ts; } // add recursive sequence template struct RecursiveSequence{ vector> add,sub; RecursiveSequence(int n):add(n),sub(n+1){} // add a_0, ..., a_{r-l-1} to [l, r) void query(int l,int r){ add[l].emplace_back(0); sub[r].emplace_back(r-l); } // a_i = \sum_{k} c_k a_{i-k} vector build(vector as,vector cs){ assert(as.size()==cs.size()); int n=add.size(); int k=as.size(); reverse(cs.begin(),cs.end()); as.resize(n+k,T(0)); for(int i=0;i ss(n+k,T(0)); for(int i=0;i struct Mint{ static constexpr T mod = MOD; T v; Mint():v(0){} Mint(signed v):v(v){} Mint(long long t){v=t%MOD;if(v<0) v+=MOD;} Mint pow(long long k){ Mint res(1),tmp(v); while(k){ if(k&1) res*=tmp; tmp*=tmp; k>>=1; } return res; } static Mint add_identity(){return Mint(0);} static Mint mul_identity(){return Mint(1);} Mint inv(){return pow(MOD-2);} Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;} Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;} Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;} Mint& operator/=(Mint a){return (*this)*=a.inv();} Mint operator+(Mint a) const{return Mint(v)+=a;} Mint operator-(Mint a) const{return Mint(v)-=a;} Mint operator*(Mint a) const{return Mint(v)*=a;} Mint operator/(Mint a) const{return Mint(v)/=a;} Mint operator-() const{return v?Mint(MOD-v):Mint(v);} bool operator==(const Mint a)const{return v==a.v;} bool operator!=(const Mint a)const{return v!=a.v;} bool operator <(const Mint a)const{return v constexpr T Mint::mod; template ostream& operator<<(ostream &os,Mint m){os<>k>>n>>q; using M = Mint; vector as(k),cs(k); for(int i=0;i>as[i].v; for(int i=0;i>cs[i].v; RecursiveSequence rs(n); for(int i=0;i>l>>r; rs.query(l,r); } auto ss=rs.build(as,cs); for(int i=0;i