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>
#define fo(a,b,c) for (a=b; a<=c; a++)
#define fd(a,b,c) for (a=b; a>=c; a--)
#define C(n,m) (jc[n]*Jc[m]%mod*Jc[(n)-(m)]%mod)
#define add(a,b) a=((a)+(b))%mod
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
#define mod 998244353
#define Mod 998244351
#define ll long long
#define G 114514
//#define file
using namespace std;

int n,i,j,k,l,A,B,s,N,N2,len;
int f[5011],g[5011],ans;
int a[16384],b[16384],w1[15][16384],w2[15][16384];
ll jc[200001],Jc[200001];
int a2[15][16384];

ll qpower(ll a,int b) {ll ans=1; while (b) {if (b&1) ans=ans*a%mod;a=a*a%mod;b>>=1;} return ans;}
void init()
{
	int i,j,k,l;
	N=1;
	fo(len,1,14)
	{
		N*=2;
		fo(i,0,N-1)
		{
			j=i,k=0;
			fo(l,1,len) k=k*2+(j&1),j>>=1;
			a2[len][i]=k;
		}
	}
	ll w,W;
	l=2;k=1;
	fo(i,1,14)
	{
		w=qpower(G,(mod-1)/l);W=1;
		fo(j,0,k-1) w1[i][j]=W,W=W*w%mod;
		w=qpower(G,(mod-1)-(mod-1)/l);W=1;
		fo(j,0,k-1) w2[i][j]=W,W=W*w%mod;
		l<<=1;k<<=1;
	}
}
void dft(int *a,int tp)
{
	static int A[16384];
	int i,j,k,l,s1=2,s2=1,S=N;
	ll u,v;
	
	fo(i,0,N-1) A[a2[len][i]]=a[i];memcpy(a,A,N*4);
	fo(i,1,len)
	{
		S>>=1;
		fo(j,0,S-1)
		{
			fo(k,0,s2-1)
			{
				if (tp==1)
				u=a[j*s1+k],v=1ll*a[j*s1+k+s2]*w1[i][k];
				else
				u=a[j*s1+k],v=1ll*a[j*s1+k+s2]*w2[i][k];
				a[j*s1+k]=(u+v)%mod;
				a[j*s1+k+s2]=(u-v)%mod;
			}
		}
		s1<<=1,s2<<=1;
	}
}

void work1()
{
	int i,j,k,l;
	memset(g,0,(s+2)*4);
	fo(i,1,s) add(g[i],f[i]),add(g[i+1],f[i]);
	++s,memcpy(f,g,(s+1)*4);
}
void work2()
{
	int i,j,k,l;
	--s;
	fo(i,1,s) g[i]=(f[i]+f[i+1])%mod;
	memcpy(f,g,(s+1)*4);
}
void work3(int t)
{
	int i,j,k,l;
	if (!t) return;
	len=ceil(log2(s+1))+1,N=qpower(2,len);N2=qpower(N,Mod);
	
	memset(a,0,N*4),memset(b,0,N*4);
	fo(i,1,s) g[i]=1ll*f[i]*C(t*2,t)%mod,a[i]=f[i];
	fo(i,1,min(s,t)) b[i]=C(t*2,t+i);
	
	dft(a,1),dft(b,1);
	fo(i,0,N-1) a[i]=1ll*a[i]*b[i]%mod;
	dft(a,-1);
	fo(i,1,s) a[i]=1ll*a[i]*N2%mod;
	fo(i,1,s) add(g[i],1ll*(a[i]+a[s-i+1]));
	memcpy(f,g,(s+1)*4);
}

int main()
{
	#ifdef file
	freopen("CF1473G.in","r",stdin);
	#endif
	
	jc[0]=1;
	fo(i,1,200000) jc[i]=jc[i-1]*i%mod;
	Jc[200000]=qpower(jc[200000],Mod);
	fd(i,200000-1,0) Jc[i]=Jc[i+1]*(i+1)%mod;
	scanf("%d",&n);s=1,f[1]=1;
	init();
	
	fo(i,1,n)
	{
		scanf("%d%d",&A,&B);
		if (A>B) {fo(j,1,A-B) work1();work3(B);}
		else {work3(A);fo(j,1,B-A) work2();}
	}
	
	fo(i,1,s) add(ans,f[i]);
	printf("%d\n",(ans+mod)%mod);
	
	fclose(stdin);
	fclose(stdout);
	return 0;
}