Problem: Snuke found a random number generator. It generates an integer between 0 and N-1 (inclusive). An integer sequence A_0, A_1, \cdots, A_{N-1} represents the probability that each of these integers is generated. The integer i (0 \leq i \leq N-1) is generated with probability A_i / S, where S = \sum_{i=0}^{N-1} A_i. The process of generating an integer is done independently each time the generator is executed.

Now, Snuke will repeatedly generate an integer with this generator until the following condition is satisfied:

* For every i (0 \leq i \leq N-1), the integer i has been generated at least B_i times so far.



Find the expected number of times Snuke will generate an integer, and print it modulo 998244353. More formally, represent the expected number of generations as an irreducible fraction P/Q. Then, there exists a unique integer R such that R \times Q \equiv P \pmod{998244353},\ 0 \leq R < 998244353, so print this R.

From the constraints of this problem, we can prove that the expected number of generations is a finite rational number, and its integer representation modulo 998244353 can be defined.

Constraints

* 1 \leq N \leq 400
* 1 \leq A_i
* \sum_{i=0}^{N-1} A_i \leq 400
* 1 \leq B_i
* \sum_{i=0}^{N-1} B_i \leq 400
* All values in input are integers.

Input

Input is given from Standard Input in the following format:


N
A_0 B_0
A_1 B_1
\vdots
A_{N-1} B_{N-1}


Output

Print the expected number of times Snuke will generate an integer, modulo 998244353.

Examples

Input

2
1 1
1 1


Output

3


Input

3
1 3
2 2
3 1


Output

971485877


Input

15
29 3
78 69
19 15
82 14
9 120
14 51
3 7
6 14
28 4
13 12
1 5
32 30
49 24
35 23
2 9


Output

371626143

Solution (in CPP):

Solution:
#include <bits/stdc++.h> 
#define EB emplace_back

typedef long long ll;
typedef std::vector <int> vector;
const int N = 432, mod = 998244353;

int n;
int A[N], B[N];
int fact[N], inv[N], finv[N];
vector Z[N];
vector buf_[4][N], *cf = *buf_, *nf = buf_[1], *cg = buf_[2], *ng = buf_[3];

inline void fma(int &x, const int y, const int z) {x = (x + (ll)y * z) % mod;}
ll PowerMod(ll a, int n, ll c = 1) {for (; n; n >>= 1, a = a * a % mod) if (n & 1) c = c * a % mod; return c;}

void init() {
	int i;
	for (inv[1] = 1, i = 2; i < N; ++i) inv[i] = ll(mod - mod / i) * inv[mod % i] % mod; 
	for (*finv = *fact = i = 1; i < N; ++i) fact[i] = (ll)fact[i - 1] * i % mod, finv[i] = (ll)finv[i - 1] * inv[i] % mod;
}

void conv_add(vector &ret, const vector &f, const vector &g) {
	int i, j, n = f.size(), m = g.size();
	if ((int)ret.size() < n + m - 1) ret.resize(n + m - 1);
	for (i = 0; i < n; ++i) for (j = 0; j < m; ++j) fma(ret[i + j], f[i], g[j]);
}

void single_add(vector &ret, const vector &f, int offset, int coeff) {
	int i, n = f.size();
	if ((int)ret.size() < n + offset) ret.resize(n + offset);
	for (i = 0; i < n; ++i) fma(ret[i + offset], f[i], coeff);
}

int main() {
	int i, j, r, S = 0, ans = 0;
	scanf("%d", &n), init();
	for (i = 0; i < n; ++i) {
		scanf("%d%d", A + i, B + i), Z[i].reserve(B[i]);
		for (r = mod - 1, j = 0; j < B[i]; r = (ll)r * A[i] % mod * inv[++j] % mod) Z[i].EB(r);
	}
	nf[0].EB(1);
	for (i = 0; i < n; S += A[i], ++i) {
		std::copy(nf, nf + (S + 1), cf), std::copy(ng, ng + (S + 1), cg);
		for (j = 0; j <= S; ++j)
			conv_add(nf[j + A[i]], cf[j], Z[i]), conv_add(ng[j + A[i]], cg[j], Z[i]),
			single_add(ng[j + A[i]], cf[j], B[i] - 1, (ll)A[i] * Z[i].back() % mod);
	}
	for (j = 1; j <= S; ++j) {
		for (r = 0, i = ng[j].size() - 1; i >= 0; --i) r = (r + (ll)fact[i + 1] * ng[j][i]) % mod * inv[j] % mod;
		ans = (ans + (ll)r * inv[j]) % mod;
	}
	printf("%d\n", ans = ll(mod - ans) * S % mod);
	return 0;
}