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<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
using namespace std;
typedef long long ll;
#define N 200015
const int p=998244353;
int n,a,b,f[N],finv[N],inv[N],rev[N],ta[N],tb[N];
inline int C(int nn,int mm){if(nn<mm||nn<0||mm<0)return 0;return 1ll*f[nn]*finv[mm]%p*finv[nn-mm]%p;}
inline int ksm(int d,int k){int ret=1;while(k){if(k&1)ret=1ll*ret*d%p;d=1ll*d*d%p;k>>=1;}return ret;}
inline void ntt(int x[],int len,int mde)
{for(int i=0;i<len;i++)if(i<rev[i])swap(x[i],x[rev[i]]);
	for(int i=2;i<=len;i<<=1)
	{int wn=ksm(3,(p-1)/i);if(mde<0)wn=ksm(wn,p-2);
		for(int j=0,stp=i>>1;j<len;j+=i)for(int k=j,w=1;k<j+stp;k++,w=1ll*w*wn%p)
		{int t1=x[k],t2=1ll*x[k+stp]*w%p;
			x[k]=(t1+t2)%p,x[k+stp]=(t1-t2+p)%p;
		}
	}if(mde<0)for(int i=0,te=ksm(len,p-2);i<len;i++)x[i]=1ll*x[i]*te%p;
}
int main()
{
	scanf("%d",&n);int len=1;f[0]=finv[0]=f[1]=finv[1]=inv[1]=1;
	for(int i=2;i<=200000;i++)
	{
		inv[i]=1ll*(p-p/i)*inv[p%i]%p;
		f[i]=1ll*f[i-1]*i%p;finv[i]=1ll*finv[i-1]*inv[i]%p;
	}ta[1]=1;
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&a,&b);
		int nl=max(len,len+a-b),tle=1;
		while(tle<=(nl*3))tle<<=1;
		for(int j=1;j<tle;j++){rev[j]=rev[j>>1]>>1;if(j&1)rev[j]|=tle>>1;}
		for(int j=len+1;j<tle;j++)ta[j]=0;for(int j=0;j<tle;j++)tb[j]=0;
		for(int j=-len;j<=nl;j++)tb[len+j]=C(a+b,b+j);
		ntt(ta,tle,1);ntt(tb,tle,1);for(int j=0;j<tle;j++)ta[j]=1ll*ta[j]*tb[j]%p;ntt(ta,tle,-1);
		for(int j=1;j<=len+a-b;j++)ta[j]=ta[j+len];
		for(int j=len+a-b+1;j<tle;j++)ta[j]=0;len+=a-b;
	}int ans=0;for(int i=1;i<=len;i++)(ans+=ta[i])%=p;printf("%d\n",ans);
}