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<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#define o 1000005
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define REP(i,a,b) for(int i=a;i>=b;i--)
#define g0(a) memset(a,0,sizeof(a))
#define gc(a,b) memcpy(a,b,sizeof(a))
#define ll long long
using namespace std;
inline int read()
{
	int data=0,w=1;
	char ch=0;
	while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
	if(ch=='-')w=-1,ch=getchar();
	while(ch>='0'&&ch<='9')data=data*10+ch-'0',ch=getchar();
	return data*w;
}
int n,m,rev[o];
const int mod=998244353;
int KSM(int x,int k)
{
	int tmp=1,y=x;
	for(int i=k;i;i>>=1,y=1ll*y*y%mod)if(i&1)tmp=1ll*tmp*y%mod;
	return tmp;
}
int Make(int n)
{
	int t=0;while(1<<t<=n)t++;
	FOR(i,0,(1<<t)-1)rev[i]=rev[i>>1]>>1|(i&1)<<t-1;
	return t; 
}
void fix(int &x){x+=x>>31&mod;}
void NTT(int a[],int n,int d)
{
	FOR(i,0,(1<<n)-1)if(i<rev[i])swap(a[i],a[rev[i]]);
	FOR(m,0,n-1)
	{
		int w=KSM(3,mod-1+(mod-1)/(2<<m)*d);
		for(int i=0;i<1<<n;i+=2<<m)
			for(int k=i,x=1;k<i+(1<<m);k++,x=1ll*x*w%mod)
			{
				int t0=a[k],t1=1ll*a[k+(1<<m)]*x%mod;
				//cout<<"x="<<x<<"\n" 
				fix(a[k]=t0+t1-mod),fix(a[k+(1<<m)]=t0-t1);
			}
	}
	if(d==-1){int iv=KSM(1<<n,mod-2);FOR(i,0,(1<<n)-1)a[i]=1ll*a[i]*iv%mod;}
}
int fac[o],inv[o],g[o],f[o],a[o];
void init(int n=300000)
{
	fac[0]=1;
	FOR(i,1,n)fac[i]=1ll*fac[i-1]*i%mod;
	inv[n]=KSM(fac[n],mod-2);
	REP(i,n-1,0)inv[i]=1ll*inv[i+1]*(i+1)%mod;
}
int C(int n,int m){return n<m||m<0?0:1ll*fac[n]*inv[m]%mod*inv[n-m]%mod;}
int main()
{
//	int p=Make(100);
//	FOR(i,0,(1<<p)-1)a[i]=1;
//	NTT(a,p,1);
//	NTT(a,p,-1);
//	FOR(i,0,(1<<p)-1)cout<<a[i]<<" ";
//	return 0;
	init(); 
	n=read(),m=1;
	f[1]=1;
	while(n--)
	{
		int A=read(),B=read(),t=Make(m+A-B+m+m);
		FOR(i,0,(1<<t)-1)a[i]=g[i]=0;
		FOR(i,-m,m+A-B)g[i+m]=C(A+B,B+i);
		FOR(i,1,m)a[i]=f[i];
		NTT(g,t,1);NTT(a,t,1);
		FOR(i,0,(1<<t)-1)g[i]=1ll*g[i]*a[i]%mod;
		NTT(g,t,-1);
		FOR(i,1,m+A-B)f[i]=g[i+m];
		m+=A-B;
		//FOR(i,1,m)cout<<f[i]<<" ";
	}
	int ans=0;
	FOR(i,1,m)fix(ans+=f[i]-mod);
	cout<<ans<<'\n';
	return 0;
}