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 ll long long
#define ljc 998244353
using namespace std;
#define gc getchar
inline ll read(){
    register ll x=0,f=1;char ch=gc();
    while (!isdigit(ch)){if (ch=='-') f=-1;ch=gc();}
    while (isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=gc();}
    return (f==1)?x:-x;
}
ll n,dp[404][404][404];
struct node{
	ll A,B;
}x[1010]; 
inline bool cmp(node a,node b){
	return a.B<b.B;
}
inline ll fast_pow(ll a,ll b,ll p){
	ll t=1;
	while (b){
		if (b&1ll) t=t*a%p;
		b>>=1ll;a=a*a%p;
	}
	return t;
}
ll sumA[1010],sumB[1010],fac[1010],inv[1010],_inv[1010],pw[404][404];
signed main(){
	n=read();
	for (int i=1;i<=n;i++){
		x[i].A=read(),x[i].B=read();
	}
	fac[0]=inv[0]=inv[1]=_inv[0]=1;
	for (ll i=1;i<=400;i++) fac[i]=i*fac[i-1]%ljc;
	for (ll i=2;i<=400;i++) inv[i]=(ljc-(ljc/i)*inv[ljc%i]%ljc)%ljc;
	for (ll i=1;i<=400;i++) _inv[i]=_inv[i-1]*inv[i]%ljc;
	sort(x+1,x+1+n,cmp);
	for (int i=1;i<=n;i++){
		sumA[i]=sumA[i-1]+x[i].A;
		sumB[i]=sumB[i-1]+x[i].B-1;
	}
	for (int i=1;i<=n;i++){
		pw[i][0]=1;
		pw[i][1]=x[i].A%ljc;
		for (int j=2;j<=400;j++){
			pw[i][j]=pw[i][j-1]*pw[i][1]%ljc;
		}
	}
	dp[0][0][0]=ljc-1;
	for (int i=1;i<=n;i++){
		for (int j=0;j<=sumA[i-1];j++){
			for (int k=0;k<=sumB[i-1];k++){
				dp[i][j][k]=(dp[i][j][k]+dp[i-1][j][k])%ljc;
				for (int l=0;l<x[i].B;l++){
					dp[i][j+x[i].A][k+l]=(dp[i][j+x[i].A][k+l]+ljc-dp[i-1][j][k]*pw[i][l]%ljc*_inv[l]%ljc)%ljc;
				}
			}
		}
	}
	ll _=0;
	for (int i=0;i<=sumA[n];i++){
		for (int j=0;j<=sumB[n];j++){
			_=(_+fac[j]*dp[n][i][j]%ljc*sumA[n]%ljc*fast_pow(i,ljc-2,ljc)%ljc*fast_pow(i,ljc-1-j,ljc)%ljc)%ljc;
		}
	}
	cout<<_;
    return 0;
}