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 unsigned long long int MAX_N = 100 * 1000 + 50;
const unsigned long long int module = 998244353;
unsigned long long int power_number(unsigned long long int number,
                                    unsigned long long int power) {
  unsigned long long int result = 1;
  while (power) {
    if (power & 1) result = (result * number) % module;
    power = power >> 1;
    number = (number * number) % module;
  }
  return result;
}
unsigned long long int mod_inverse(unsigned long long int number) {
  return power_number(number, module - 2);
}
unsigned long long int revers_f[MAX_N];
unsigned long long int f[MAX_N];
unsigned long long int root_answer[MAX_N];
unsigned long long int n, a, b, root_count;
void make_f() {
  revers_f[0] = f[0] = 1;
  for (int i = 1; i < MAX_N; ++i) {
    revers_f[i] = (revers_f[i - 1] * mod_inverse(i)) % module;
    f[i] = (f[i - 1] * i) % module;
  }
}
unsigned long long int combinaion(unsigned long long int n,
                                  unsigned long long int m) {
  return (((f[n] * revers_f[m]) % module) * revers_f[n - m]) % module;
}
void solve() {
  cin >> a >> b;
  unsigned long long int temp_root_count = root_count + a - b;
  unsigned long long int temp_row_answer[MAX_N];
  fill(temp_row_answer, temp_row_answer + MAX_N, 0);
  unsigned long long int start = ((root_count + a + b) - temp_root_count) / 2;
  unsigned long long int end = start + temp_root_count - 1;
  for (unsigned long long int i = 0; i < root_count; ++i) {
    for (unsigned long long int j = max(start, i); j <= min(i + a + b, end);
         ++j) {
      temp_row_answer[j - start] =
          (temp_row_answer[j - start] +
           ((combinaion(a + b, j - i) * root_answer[i]) % module)) %
          module;
    }
  }
  for (int i = 0; i < temp_root_count; ++i) {
    root_answer[i] = temp_row_answer[i];
  }
  root_count = temp_root_count;
  if (root_count >= 3000) {
    cout << "OH" << endl;
  }
}
int main() {
  cin >> n;
  make_f();
  root_count = 1;
  root_answer[0] = 1;
  while (n--) solve();
  unsigned long long int answer = 0;
  for (int i = 0; i < root_count; ++i) {
    answer = (answer + root_answer[i]) % module;
  }
  cout << answer << endl;
  return 0;
}
