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>
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define fi first
#define se second
using namespace std;

typedef long long LL;
typedef pair <int, int> P;
const int inf = 0x3f3f3f3f, N = 5005, mod = 998244353, M = 6e5 + 10;
template <typename T>
void rd_(T &x) {
	x = 0; int f = 1;
	char ch = getchar();
	for (; ch > '9' || ch < '0'; ch = getchar()) if (ch == '-') f = -1;
	for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x*10 + ch - '0';
	x *= f;
}

LL fpow_(LL a, LL b, LL res = 1) {
	for (; b; b >>= 1, a = a*a%mod)
		if (b&1) res = res*a%mod;
	return res;
}

int n, a, b, f[M], g[M], len, tr[M], tot, tk, R = 3, iR = fpow_(3, mod - 2);
LL fac[M], inv[M], ans; 

void init_(int n) {
	fac[0] = inv[0] = 1;
	rep (i, 1, n) fac[i] = fac[i - 1]*i%mod;
	inv[n] = fpow_(fac[n], mod - 2);
	per (i, n - 1, 1) inv[i] = inv[i + 1]*(i + 1)%mod;
}

void ntt_(int *a, int f = 1) {
	rep (i, 0, len - 1)
		if (i < tr[i]) swap(a[i], a[tr[i]]);
	for (int l = 2; l <= len; l <<= 1) {
		int wn = fpow_(f == 1 ? R : iR, (mod - 1)/l);
		for (int j = 0; j < len; j += l) {
			int w = 1;
			for (int k = 0; k < l/2; k++) {
				int u = a[j + k], v = 1ll*a[j + k + l/2]*w%mod;
				a[j + k] = (u + v)%mod, a[j + k + l/2] = (u - v + mod)%mod;
				w = 1ll*w*wn%mod;
			}
		}
	}
	if (f == -1) {
		int iL = fpow_(len, mod - 2);
		rep (i, 0, len - 1)
			a[i] = 1ll*a[i]*iL%mod;
	}
}

int main() {
	rd_(n), init_(600000);
	f[0] = 1, tot = 0;
	rep (T, 1, n) {
		rd_(a), rd_(b);
		for (len = 1, tk = 0; len <= 3*tot + a - b; len <<= 1) tk++;
		rep (i, 0, len - 1) {
			tr[i] = (tr[i>>1]>>1) | ((i&1)<<tk - 1);
			g[i] = 0;
		}
		rep (i, 0, tot + tot + a - b)
			if (b + (i - tot) >= 0 && a - (i - tot) >= 0) 
				g[i] = inv[b + (i - tot)]*inv[a - (i - tot)]%mod;
		rep (i, tot + 1, len - 1) f[i] = 0;
		ntt_(f), ntt_(g);
		rep (i, 0, len - 1) f[i] = 1ll*f[i]*g[i]%mod;
		ntt_(f, -1);
		rep (i, 0, tot + a - b)
			f[i] = f[i + tot]*fac[a + b]%mod;
		tot += a - b;
	}
	rep (i, 0, tot)
		ans = (ans + f[i])%mod;
	printf("%lld\n", ans);
}