Problem: Consider a road consisting of several rows. Each row is divided into several rectangular tiles, and all tiles in the same row are equal. The first row contains exactly one rectangular tile. Look at the picture below which shows how the tiles are arranged.

The road is constructed as follows: 

  * the first row consists of 1 tile; 
  * then a_1 rows follow; each of these rows contains 1 tile greater than the previous row; 
  * then b_1 rows follow; each of these rows contains 1 tile less than the previous row; 
  * then a_2 rows follow; each of these rows contains 1 tile greater than the previous row; 
  * then b_2 rows follow; each of these rows contains 1 tile less than the previous row; 
  * ... 
  * then a_n rows follow; each of these rows contains 1 tile greater than the previous row; 
  * then b_n rows follow; each of these rows contains 1 tile less than the previous row. 

<image> An example of the road with n = 2, a_1 = 4, b_1 = 2, a_2 = 2, b_2 = 3. Rows are arranged from left to right. 

You start from the only tile in the first row and want to reach the last row (any tile of it). From your current tile, you can move to any tile in the next row which touches your current tile.

Calculate the number of different paths from the first row to the last row. Since it can be large, print it modulo 998244353.

Input

The first line contains one integer n (1 ≤ n ≤ 1000).

Then n lines follow. The i-th of them contains two integers a_i and b_i (1 ≤ a_i, b_i ≤ 10^5; |a_i - b_i| ≤ 5).

Additional constraint on the input: the sequence of a_i and b_i never results in a row with non-positive number of tiles.

Output

Print one integer — the number of paths from the first row to the last row, taken modulo 998244353.

Examples

Input


2
4 2
2 3


Output


850


Input


3
4 1
2 3
3 1


Output


10150


Input


8
328 323
867 868
715 718
721 722
439 435
868 870
834 834
797 796


Output


759099319

Solution (in CPP):

Solution:
#include<bits/stdc++.h>
typedef int LL;
typedef double dl;
#define opt operator
#define pb push_back
#define pii std::pair<LL,LL>
const LL maxn=1e6+9,mod=998244353,inf=0x3f3f3f3f,G=3;
LL Read(){
	LL x(0),f(1); char c=getchar();
	while(c<'0' || c>'9'){
		if(c=='-') f=-1; c=getchar();
	}
	while(c>='0' && c<='9'){
		x=(x<<3ll)+(x<<1ll)+c-'0'; c=getchar();
	}return x*f;
}
void Chkmin(LL &x,LL y){
	if(y<x) x=y;
}
void Chkmax(LL &x,LL y){
	if(y>x) x=y;
}
LL add(LL x,LL y){
	return x+=y,x>=mod?x-mod:x;
}
LL dec(LL x,LL y){
	return x-=y,x<0?x+mod:x;
}
LL mul(LL x,LL y){
	return 1ll*x*y%mod;
}
LL Pow(LL base,LL b){
	LL ret(1); while(b){
		if(b&1) ret=mul(ret,base); base=mul(base,base); b>>=1;
	}return ret;
}
namespace Poly{
	LL r[maxn];
	LL Fir(LL N){
		LL limit(1),len(0);
		while(limit<N) limit<<=1,++len;
		for(LL i=1;i<limit;++i) r[i]=(r[i>>1]>>1)|((i&1)<<len-1);
		return limit;
	}
	void Ntt(LL *A,LL N,LL op){
		for(LL i=1;i<N;++i) if(i<r[i]) std::swap(A[i],A[r[i]]);
		for(LL len=1;len<N;len<<=1){
			LL wn(Pow(G,(mod-1)/(len<<1))); if(op==-1) wn=Pow(wn,mod-2);
			for(LL j=0;j<N;j+=(len<<1)){
				for(LL k=0,w=1;k<len;++k,w=mul(w,wn)){
					LL x(A[j+k]),y(mul(w,A[j+k+len]));
					A[j+k]=add(x,y); A[j+k+len]=dec(x,y);
				}
			}
		}
		if(op==-1){
			LL Tmp(Pow(N,mod-2));
			for(LL i=0;i<N;++i) A[i]=mul(A[i],Tmp);
		}
	}
	void Mul(LL *A,LL *B,LL *C,LL N,LL M,LL len){
		static LL tA[maxn],tB[maxn];
		LL limit(Fir(N+M-1));
		for(LL i=0;i<N;++i) tA[i]=A[i]; for(LL i=N;i<limit;++i) tA[i]=0;
		for(LL i=0;i<M;++i) tB[i]=B[i]; for(LL i=M;i<limit;++i) tB[i]=0;
		Ntt(tA,limit,1); Ntt(tB,limit,1);
		for(LL i=0;i<limit;++i) tA[i]=mul(tA[i],tB[i]);
		Ntt(tA,limit,-1);
        for(LL i=0;i<limit;++i) C[i]=tA[i];
		for(LL i=limit;i<len;++i) C[i]=0;
	}
}
LL n;
LL a[maxn],b[maxn],fav[maxn],fac[maxn],f[maxn],h[maxn];
LL C(LL N,LL M){
	if(M<0) return 0;
    if(N<M) return 0;
	return 1ll*fac[N]*fav[M]%mod*fav[N-M]%mod;
}
void Fir(){
	LL N(1000000);
	fac[0]=1; for(LL i=1;i<=N;++i) fac[i]=mul(fac[i-1],i);
	fav[N]=Pow(fac[N],mod-2); for(LL i=N;i>=1;--i) fav[i-1]=mul(fav[i],i);
}
int main(){
	Fir();
	n=Read();
	for(LL i=1;i<=n;++i){
		a[i]=Read(); b[i]=Read();
	}
	LL num(1);
	f[num]=1;
	LL V(0);
	for(LL l=1;l<=n;++l){
		LL _num(num+a[l]-b[l]);
		LL len1(a[l]),len2(b[l]);
		static LL A[maxn],B[maxn],C[maxn],F[maxn];
		A[0]=0;
		for(LL i=1;i<=num;++i) A[i]=f[i];
		for(LL i=0;i<=V+len1;++i) B[i]=0;
		LL L(std::max(-len2,-num+1)),R(std::min(len1,_num));
		LL tlen(len2-L);
		/*
		V=len2;
		for(LL i=-len2;i<=len1;++i) B[V+i]=mul(fav[len1-i],fav[len2+i]);
		printf("%d,%d,%d\n",num+1,V+len1+1,V+_num+1);
		Poly::Mul(A,B,C,num+1,V+len1+1,V+_num+1);
		*/
		V=-L;
		for(LL i=L;i<=R;++i) B[V+i]=mul(fav[len1-i],fav[len2+i]);
		Poly::Mul(A,B,C,num+1,V+R+1,V+_num+1);
		LL tmp(fac[len1+len2]);
		for(LL i=1;i<=_num;++i) f[i]=mul(tmp,C[V+i]);
//		for(LL i=1;i<=_num;++i) printf("%d ",f[i]); puts("");
		num=_num;
	}
	LL ans(0);
	for(LL i=1;i<=num;++i) ans=add(ans,f[i]);
	printf("%d\n",ans);
	return 0;
}