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>
using namespace std;
using ll = long long;
#define endl '\n'
#define all(v) (v).begin(), (v).end()
template<class A, class B> ostream& operator<<(ostream& os, const pair<A,B>& p) {
	return os << '(' << p.first << ", " << p.second << ')';
}
template<class T> auto operator<<(ostream& os, T&& x) -> decltype(x.begin(), os) {
	os << '{';
	for(auto it = x.begin(); it != x.end(); ++it) os << *it << (it == prev(x.end()) ? "" : ", ");
	return os << '}';
}
void dump() {}
template<class T,class... Args> void dump(T&& x,Args... args) { cerr<<x<<";  "; dump(args...); }
#ifdef DEBUG
    struct Lf{ ~Lf() { cerr << '\n'; } };
    #define debug(x...) cerr << (strcmp(#x, "") ? #x ":  " : ""), dump(x), Lf(), cerr << ""
#else
    #define debug(...) 0&&cerr
#endif

const int MAX = 1<<23;		//max input vector length
const int MOD = 998244353;	//prime modulus e.g. 998244353 = 1 + 7*17*2^23
const int G = 3;			//generator for Z_MOD
 
int modpow(int base, int exp) {
  base %= MOD;
  int result = 1;
  while (exp > 0) {
	if (exp & 1) result = (1ll*result * base) % MOD;
	base = (1ll*base * base) % MOD;
	exp >>= 1;
  }
  return result;
}
int modinv(int a) {
    return modpow(a,MOD-2);
}
//FFT=1 for transform, FFT=-1 for inverse transform; N=current input length, should use a power of 2
void fft(vector<int>& a, int FFT, int N) {
    static int rev[MAX];
    for (int i = 0; i < N; i++) {
		rev[i] = (rev[i>>1]>>1)|((i&1)?(N>>1):0);
        if (i < rev[i]) swap(a[i], a[rev[i]]);
    }
    for (int m = 2, m2 = 1; m <= N; m <<= 1, m2 <<= 1) {
        int wm = modpow(G, (MOD-1)/m*FFT+(FFT==-1?MOD-1:0));
        for (int k = 0; k < N; k += m)
            for (int j = 0, u, t, w = 1; j < m2; j++)
                t = 1ll*w*a[k+j+m2]%MOD, u = a[k+j], w = 1ll*w*wm%MOD,
                a[k+j] = (u+t)%MOD, a[k+j+m2] = (u-t+MOD)%MOD;
    }
    if (FFT == -1)
        for (int i = 0, invN = modinv(N); i < N; i++)
            a[i] = 1ll * a[i] * invN % MOD;
}
 
int degp,degq;
vector<int> P,Q;

void mul() {
    int N=1;
	for (; N<degp+degq+1; N<<=1);
	while ((int)P.size()<N) P.push_back(0);
	while ((int)Q.size()<N) Q.push_back(0);
	
	fft(P,1,N);
	fft(Q,1,N);
	for (int i=0; i<N; ++i) P[i] = (1ll*P[i]*Q[i])%MOD;
	fft(P,-1,N);
	while (P.back()==0) P.pop_back();
}

int n, a,b, fact[200010], ifact[200010];
void calc() {
    fact[0] = 1, fact[1] = 1, ifact[0] = 1, ifact[1] = 1;
    for (int i=2; i<=200000; ++i) {
        fact[i] = (1ll*fact[i-1]*i) % MOD;
        ifact[i] = modinv(fact[i]);
    }
}
int C(int x, int y) {
    if (y<0 || y>x) return 0;
    int div = (1ll*ifact[y]*ifact[x-y])%MOD;
    return (1ll*fact[x]*div)%MOD;
}

int main() {
    ios::sync_with_stdio(false);
    calc();
    cin >> n;
    P = {1};
    for (int i=0; i<n; ++i) {
        cin >> a >> b;
        int m = P.size();
        Q.clear();
        for (int j=b-m+1; j<m+a; ++j) Q.push_back(C(a+b,j));
        degp = m-1;
        degq = Q.size()-1;
        mul();
        for (int j=0; j<m+a-b; ++j) P[j] = P[m+j-1];
        P.resize(m+a-b);
    }
    int sum = 0;
    for (int x : P) {
        sum = (sum+x) % MOD;
    }
    cout << sum << endl;

	return 0;
}