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
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 20, MAXV = 1e5 + 20, M = 998244353;
namespace Number_Theory_base {
inline int mul(const int &x, const int &y, const int &M) {
  return 1ll * x * y % M;
}
int Pow(int x, int k, const int &M) {
  int ret = 1;
  for (; k; k >>= 1, x = mul(x, x, M))
    if (k & 1) ret = mul(ret, x, M);
  return ret;
}
int fact[MAXV * 2], fact_inv[MAXV * 2];
void pre_Fact() {
  fact[0] = 1;
  for (int i = 1; i < MAXV * 2; ++i) fact[i] = mul(fact[i - 1], i, M);
  fact_inv[MAXV * 2 - 1] = Pow(fact[MAXV * 2 - 1], M - 2, M);
  for (int i = MAXV * 2 - 1 - 1; i >= 0; --i)
    fact_inv[i] = mul(fact_inv[i + 1], i + 1, M);
}
inline int Fact(const int &x) { return fact[x]; }
inline int Fact_Inv(const int &x) { return fact_inv[x]; }
}  // namespace Number_Theory_base
using namespace Number_Theory_base;
int n, m;
const int MAXN_Poly = 1 << 14;
namespace Poly_base {
struct Poly {
  int N;
  int data[MAXN_Poly];
  Poly() : N(0) { memset(data, 0, sizeof(data)); }
  Poly(const int &_N) : N(_N) { memset(data, 0, sizeof(data)); }
  int &operator[](const int &index) { return data[index]; }
  int operator[](const int &index) const { return data[index]; }
};
}  // namespace Poly_base
using namespace Poly_base;
namespace Poly_calc {
namespace Poly_calc_base {
const int M_NTT = 998244353, g_NTT = 3;
int S[MAXN_Poly];
bool op;
void NTT_pre(const int &N) {
  int shift_of_highest_bit = 0;
  while (N >= (1 << (shift_of_highest_bit + 1))) ++shift_of_highest_bit;
  --shift_of_highest_bit;
  for (int i = 0; i < N; ++i)
    S[i] = (S[i >> 1] >> 1) | ((i & 1) << shift_of_highest_bit);
  op = 1;
}
inline void NTT_rev_op() { op ^= 1; }
inline void swap(int &x, int &y) { x ^= y ^= x ^= y; }
void NTT(Poly &A) {
  for (int i = 0; i < A.N; ++i)
    if (i < S[i]) swap(A[i], A[S[i]]);
  for (int N = 1; N < A.N; N <<= 1) {
    const int wn =
        (op) ? Pow(g_NTT, (M_NTT - 1) / (N << 1), M_NTT)
             : Pow(Pow(g_NTT, (M_NTT - 1) / (N << 1), M_NTT), M_NTT - 2, M_NTT);
    for (int shift_A = 0; shift_A < A.N; shift_A += (N << 1)) {
      int w = 1, *f0 = &A[0] + shift_A, *f1 = &A[0] + shift_A + N;
      for (int i = 0; i < N; ++i) {
        const int res = mul(*f1, w, M_NTT);
        *f1 = (*f0 - res + M_NTT) % M_NTT, *f0 = (*f0 + res) % M_NTT;
        w = mul(w, wn, M_NTT), ++f0, ++f1;
      }
    }
  }
}
}  // namespace Poly_calc_base
using namespace Poly_calc_base;
int get_Result_N(const int &limit) {
  int N = 1;
  while (N < limit) N <<= 1;
  return N;
}
void conv(Poly &A, Poly &B, Poly &Result) {
  const int N = Result.N = A.N = B.N = get_Result_N(A.N + B.N - 1);
  NTT_pre(N);
  NTT(A), NTT(B);
  const int Inv_N = Pow(N, M_NTT - 2, M_NTT);
  for (int i = 0; i < N; ++i)
    Result[i] = mul(mul(A[i], B[i], M_NTT), Inv_N, M_NTT);
  NTT_rev_op();
  NTT(Result);
}
}  // namespace Poly_calc
using namespace Poly_calc;
static char buf[1000000], *p1 = buf, *p2 = buf;
inline int read() {
  register int x = 0;
  register char a = getchar();
  while (a < '0' || a > '9') a = getchar();
  while (a >= '0' && a <= '9') x = x * 10 + (a ^ 48), a = getchar();
  return x;
}
signed main() {
  n = read();
  pre_Fact();
  int asdf = n;
  n = 1;
  Poly A(1);
  A[0] = 1;
  int flag = 0;
  for (int i = 1; i <= asdf; ++i) {
    int a, b;
    a = read();
    b = read();
    int ori = n;
    Poly B(n + a - b + n);
    for (int i = 0, j = b - n + 1; j <= n + a; ++j, ++i)
      if (j >= 0 && a + b - j >= 0)
        B[i] = fact_inv[a + b - j] * fact_inv[j] % 998244353;
    conv(A, B, A);
    n = n + a - b;
    for (int j = 0; j <= n; ++j)
      (A[j] = fact[a + b] * A[ori + j - 1] % 998244353) %= 998244353;
    for (int j = n; j <= get_Result_N(A.N + B.N + 1); ++j) A[j] = 0;
    A.N = n;
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) (ans += A[i]) %= 998244353;
  printf("%d", ans);
}
