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 <cstdio>
#include <cstring> 

using namespace std;
const int MOD(998244353);
const int Max_N(405);
const int Max_SumA(405);
const int Max_SumB(405);
typedef long long int LL;

constexpr int Mult(int a, int b)
{
	return a * 1LL * b % MOD;
}

constexpr int Add(int a, int b)
{
	return a + b >= MOD ? a + b - MOD : a + b;
}

constexpr int Sub(int a, int b)
{
	return a - b < 0 ? a - b + MOD : a - b;
}

constexpr int squ(int a)
{
	return Mult(a, a);
}

void exgcd(int a, int b, int &x, int &y)
{
	if (b == 0)
		x = 1, y = 0;
	else
		exgcd(b, a % b, y, x), y -= x * (a / b);
}

inline int inverse(int a)
{
	int invx, invy;
	exgcd(a, MOD, invx, invy);
	return (invx % MOD + MOD) % MOD;
}

inline void upd(int &a, int b)
{
	a = Add(a, b);
}

inline void inc(int &a, int b)
{
	a = Sub(a, b);
}

int N, A[Max_N], B[Max_N], F[2][Max_SumA][Max_SumB][2], Fac[Max_SumB], Inv[Max_SumB], now, lst;

inline int merge(int a, int b)
{
	return Mult(Fac[a + b], Mult(Inv[a], Inv[b]));
}

int main()
{
	scanf("%d", &N);
	for (int i = 1;i <= N;++i)
		scanf("%d%d", A + i, B + i), B[0] += B[i];
	Fac[0] = 1;
	for (int i = 1;i <= B[0];++i)
		Fac[i] = Mult(Fac[i - 1], i);
	Inv[B[0]] = inverse(Fac[B[0]]);
	for (int i = B[0] - 1;i >= 0;--i)
		Inv[i] = Mult(Inv[i + 1], i + 1);
	B[0] = 0;
	F[0][0][0][0] = Sub(0, 1), now = 0, lst = 1;
	for (int i = 1;i <= N;++i)
	{
		now ^= 1, lst ^= 1, memset(F[now], 0, sizeof(F[now]));
		for (int cnt = 0;cnt <= B[0];++cnt)
			for (int sump = 0, p;sump <= A[0];++sump)
			{
				for (int c = 0;c <= 1;++c)
				{
					if (!F[lst][cnt][sump][c])
						continue;
					upd(F[now][cnt][sump][c], F[lst][cnt][sump][c]);
					p = 1;
					for (int x = 0;x < B[i];++x, p = Mult(p, A[i]))
						inc(F[now][cnt + x][sump + A[i]][c], Mult(Mult(F[lst][cnt][sump][c], merge(cnt, x)), p));
				}
				if (!F[lst][cnt][sump][0])
					continue;
				p = 1;
				for (int x = 1;x <= B[i];++x)
					p = Mult(p, A[i]);
				inc(F[now][cnt + B[i] - 1][sump + A[i]][1], Mult(Mult(F[lst][cnt][sump][0], merge(cnt, B[i] - 1)), p));
			}
		B[0] += B[i], A[0] += A[i];
	}
	int Ans(0);
	for (int cnt = 0;cnt <= B[0];++cnt)
		for (int sump = 0, p, val, inv;sump <= A[0];++sump)
		{
			if (!(val = F[now][cnt][sump][1]))
				continue;
			p = Mult(sump, inverse(A[0]));
			val = Mult(val, Mult(cnt + 1, inverse(p))); 
			inv = inverse(sump);
			for (int i = 1;i <= cnt + 1;++i)
				val = Mult(val, inv);
			upd(Ans, val);
		}
	printf("%d", Ans);
	return 0;
}