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;
using base = ll;//complex<double>;
const ll mod = 998244353;
ll mexp(ll x, ll y) {
    ll r = 1;
    for(;y;x=x*x%mod, y>>=1) if(y & 1) r = r * x % mod;
    return r;
}
ll modd(ll x) {
    if(x >= mod) x -= mod;
    if(x < 0) x += mod;
    return x;
}
base roots[1<<20];
void fft(vector<base>& a, bool inv) {
    int n = a.size(), j = 0;
    for(int i=1;i<n;i++) {
        int bit = (n >> 1);
        while(j >= bit) {
            j -= bit;
            bit >>= 1;
        }
        j += bit;
        if(i < j) swap(a[i], a[j]);
    }
    // In NTT, let prr = primitive root. Then,
    int prr = 3;
    ll ang = mexp(prr, (mod - 1) / n);
    if(inv) ang = mexp(ang, mod - 2);
    roots[0] = 1;
    for(int i=1; i<n/2; i++){
        roots[i] = roots[i-1] * ang % mod;
    }
    //also, make sure to apply modulus under here
    for(int i=2;i<=n;i<<=1) {
        int step = n / i;
        for(int j=0;j<n;j+=i) {
            for(int k=0;k<i/2;k++) {
                base u = a[j+k], v = a[j+k+i/2] * roots[step * k] % mod;
                a[j+k] = modd(u+v);
                a[j+k+i/2] = modd(u-v+mod);
            }
        }
    }
    if(inv) for(int i=0;i<n;i++) a[i] = a[i] * mexp(n, mod-2) % mod;
}
void conv(vector<base>& x, vector<base>& y) {
    int n = 2; while(n < x.size()+y.size()) n <<= 1;
    x.resize(n), y.resize(n);
    fft(x, false); fft(y, false);
    for(int i=0;i<n;i++) x[i] = x[i] * y[i] % mod;
    fft(x, true);
}
const int lim = 222222;
ll f[lim], fi[lim];
vector<base> ans, mul, nans;
int n;
ll binom(int a, int b) {
    if(b < 0 || b > a) return 0;
    return f[a] * fi[b] % mod * fi[a-b] % mod;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    ans.reserve(1<<16);
    mul.reserve(1<<16);
    f[0] = 1;
    for(int i=1;i<lim;i++)
        f[i] = i * f[i-1] % mod;
    fi[lim-1] = mexp(f[lim-1], mod-2);
    for(int i=lim-2;i>=0;i--)
        fi[i] = (i+1) * fi[i+1] % mod;
    ans.push_back(1);
    for(int i=0;i<n;i++) {
        int a, b;
        cin >> a >> b;
        int m = ans.size();
        int m1 = 2 * m + a - b - 1;
        for(int j=0;j<m1;j++)
            mul.emplace_back(binom(a+b, b+j-(m-1)));
        conv(ans, mul);
        nans.clear(); nans.resize(m+a-b);
        for(int i=0;i<m+a-b;i++) nans[i] = ans[m-1+i];
        ans = nans;
        mul.clear();
    }
    cout << accumulate(ans.begin(), ans.end(), 0LL) % mod;
}