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>

#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif

using namespace std;

const int MOD=998244353, PR=3;
vector<int> X, Y;
int F[300001], Finv[300001];

int mul(int a, int b) {return 1LL*a*b%MOD;}

int fast_pow(int a, int b)
{
    int ret=1;
    for(;b;b>>=1) {
        if(b&1) ret=mul(ret,a);
        a=mul(a,a);
    }
    return ret;
}

void FFT(vector<int> &A,bool inv)
{
	int N=A.size();
    stack<int> S;
	for(int i=0;i<N;i++) {
		int j=0;
		for(int b=1;b<N;b<<=1) {
			j<<=1;
			if(b&i) j|=1;
		}
		if(i<j) swap(A[i],A[j]);
	}
    S.push(fast_pow(inv ? fast_pow(PR,MOD-2):PR,MOD/N));
    for(int i=2;i<N;i<<=1) S.push(mul(S.top(),S.top()));
	for(int i=1;i<N;i<<=1) {
        int w=S.top();
        S.pop();
		for(int j=0;j<N;j+=i<<1) {
			int th=1;
			for(int k=0;k<i;k++) {
				int temp=mul(A[i+j+k],th);
				A[i+j+k]=A[j+k]-temp;
                if(A[i+j+k]<0) A[i+j+k]+=MOD;
				A[j+k]+=temp;
                if(A[j+k]>=MOD) A[j+k]-=MOD;
                th=mul(th,w);
			}
		}
	}
	if(inv) {
        int v=fast_pow(N,MOD-2);
        for(int i=0;i<N;i++) A[i]=mul(A[i],v);
    }
}

void conv(vector<int> &A, vector<int> &B)
{
	int N=1;
	for(;N<A.size()+B.size();N<<=1);
	A.resize(N); B.resize(N);
	FFT(A,false); FFT(B,false);
	for(int i=0;i<N;i++) A[i]=mul(A[i],B[i]);
	FFT(A,true);
}

int nCr(int n, int r)
{
	return mul(F[n],mul(Finv[r],Finv[n-r]));
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt","r",stdin));
	TEST(freopen("output.txt","w",stdout));
	TEST(freopen("debug.txt","w",stderr));
	int N=1, M, ans=0;
	F[0]=Finv[0]=1;
	for(int i=1;i<=300000;i++) F[i]=mul(i,F[i-1]);
	Finv[300000]=fast_pow(F[300000],MOD-2);
	for(int i=300000;--i;) Finv[i]=mul(Finv[i+1],i+1);
	X.resize(1,1);
	for(cin>>M;M--;) {
		int a, b, sz=X.size()+10;
		cin>>a>>b;
		Y.clear();
		for(int i=-sz;i<=sz;i++) {
			if(b+i<0 || i>a) Y.push_back(0);
			else Y.push_back(nCr(a+b,b+i));
		}
		conv(X,Y);
		N+=a-b;
		for(int i=0;i<N;i++) X[i]=X[sz+i];
		X.resize(N);
	}
	for(int i=0;i<N;i++) {
		ans+=X[i];
		if(ans>=MOD) ans-=MOD;
	}
	cout<<ans<<'\n';
	return 0;
}