#include using namespace std; template struct modint { modint():value(0){} modint(long long v) { long long x=(long long)(v%m()); if(x<0)x+=m(); value=x; } static modint raw(long long v) { modint x; x.value=v; return x; } static constexpr long long mod()noexcept{return m();} long long val()const{return value;} modint& operator++() { value++; if(value==m())value=0; return *this; } modint& operator--() { if(value==0)value=m(); value--; return *this; } modint operator++(int) { modint res=*this; ++*this; return res; } modint operator--(int) { modint res=*this; --*this; return res; } modint& operator+=(const modint& a) { value+=a.value; if(value>=m())value-=m(); return *this; } modint& operator-=(const modint& a) { value-=a.value; if(value<0)value+=m(); return *this; } modint& operator*=(const modint& a) { unsigned long long x=value; x*=a.value; x%=m(); if(x<0)x+=m(); value=x; return *this; } modint& operator/=(const modint& a) { return *this=(*this)*a.inv(); } modint operator+()const{return *this;} modint operator-()const{return modint()-*this;} modint pow(long long n)const { modint x=*this,res=1; while(n) { if(n&1)res*=x; x*=x; n>>=1; } return res; } modint inv()const { long long a=value,b=m(),u=1,v=0; while(b) { long long t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); } return modint(u); } friend modint operator+(const modint& a, const modint& b) { modint res=a; res+=b; return res; } friend modint operator-(const modint& a, const modint& b) { modint res=a; res-=b; return res; } friend modint operator*(const modint& a, const modint& b) { modint res=a; res*=b; return res; } friend modint operator/(const modint& a, const modint& b) { modint res=a; res/=b; return res; } friend bool operator==(const modint& a, const modint& b) { return a.value==b.value; } friend bool operator!=(const modint& a, const modint& b) { return a.value!=b.value; } private: long long value; static constexpr long long m(){return mod_;} }; template struct combination { combination(int n=0):inner_fac(1,1),inner_finv(1,1){init(n);} mint fac(int n) { init(n); return inner_fac[n]; } mint finv(int n) { init(n); return inner_finv[n]; } mint inv(int n) { if(n==0)return 0; init(n); return inner_fac[n-1]*inner_finv[n]; } mint C(int n, int r) { if(r<0)return 0; if(n<0) { n=-n; mint res=C(n-1+r,r); if(r&1)res=-res; return res; } if(ninner_fac,inner_finv; void init(int n) { int sz=inner_fac.size(); if(sz>n)return; n=min(max(n,2*sz),bound); inner_fac.resize(n+1); inner_finv.resize(n+1); for(int i=sz;i<=n;i++)inner_fac[i]=inner_fac[i-1]*i; inner_finv[n]=inner_fac[n].inv(); for(int i=n;i>sz;i--)inner_finv[i-1]=inner_finv[i]*i; } }; struct Mo { Mo(int _n, int _q):n(_n),q(_q){querys.reserve(_n);} void add(int l, int r){querys.emplace_back(l,r);} template void build(const ExL&exl, const ShL&shl, const ExR&exr, const ShR&shr, const O&out) { const int b=n/min(n,(int)sqrt(n)); vectoridx(q); for(int i=0;irj:bili)exl(--l); while(rri)shr(--r); out(i); } } private: int n,q; vector>querys; }; using mint=modint<998244353>; combinationC; vectormultipoint_binomial_sum(const vector>& qs) { auto binom=[&](int n, int k){return C.C(n,k);}; int n_max=2,q=qs.size(); for(auto[n,k]:qs)n_max=max(n_max,n); Mo mo(n_max,q); for(auto[n,k]:qs)mo.add(k,n); vectorres(q); int n=0,k=0; mint ans=1; const mint inv2=mint(2).inv(); auto exl=[&](int i){ans-=binom(n,k--);}; auto shl=[&](int i){ans+=binom(n,++k);}; auto exr=[&](int i){ans+=ans-binom(n++,k);}; auto shr=[&](int i){ans=(ans+binom(--n,k))*inv2;}; auto out=[&](int i){res[i]=ans;}; mo.build(exl,shl,exr,shr,out); return res; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int Q; cin>>Q; vector>qs(Q); for(auto&p:qs) { int n,k; cin>>n>>k; p=make_pair(n-1,k-1); } auto binom=multipoint_binomial_sum(qs); for(int i=0;i