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>
using namespace std;

const int maxn = 400+3;
const int maxm = 800+3;
const int mod = 998244353;
int nw[maxn][maxm];
int dp[maxn][maxm];
int a[maxn],b[maxn],s;
int sn,sm,n;
int fact[maxm],finv[maxm],invs[maxm];
inline int add(int a,int b){
	a+=b;
	if(a>=mod)	return a-mod;
	return a;
}
inline int sub(int a,int b){
	a-=b;
	if(a<0)	return a+mod;
	return a;
}
int mul(int a,int b){
	long long t=1ll*a*b;
	return t-t/mod*mod;
}
inline int qp(int a,int b){
	int ans=1;
	while(b){
		if(b&1)	ans=mul(ans,a);
		a=mul(a,a);
		b>>=1;
	}
	return ans;
}
inline void tran(){
	dp[0][0]=1;
	int t,p,d;
	for(int i=0;i<n;++i){
		p=mul(a[i],invs[s]);
		for(int ii=sn;ii>=0;--ii)
			for(int jj=sm;jj>=0;--jj){
				if(!dp[ii][jj])	continue;
				t=dp[ii][jj];	dp[ii][jj]=0;
				dp[ii+a[i]][jj]=add(dp[ii+a[i]][jj],t);
				for(int k=0,d=1;k<b[i];++k,d=mul(d,p))
					dp[ii][jj+k]=sub(dp[ii][jj+k],mul(mul(finv[k],d),t));
			}
		sn+=a[i];
		sm+=b[i];
	}
	/*for(int ii=0;ii<=sn;++ii)
	{
		for(int jj=0;jj<=sm;++jj)
			cout<<dp[ii][jj]<<" ";
		cout<<endl;
	}*/
}
inline int get(int ai,int bi){
	int t,p=mul(ai,invs[s]);
	for(int ii=0;ii<=sn;++ii)
		for(int jj=0;jj<=sm;++jj)
			nw[ii][jj]=dp[ii][jj];
	for(int ii=0;ii<=sn;++ii)
		for(int jj=0;jj<=sm;++jj){
			if(bi)	nw[ii][jj]=sub(0,nw[ii][jj]);
			if(!nw[ii][jj])	continue;
			t=nw[ii][jj];
			nw[ii+ai][jj]=sub(nw[ii+ai][jj],t);
			for(int k=1,d=p;k<bi;++k,d=mul(d,p))
				nw[ii][jj+k]=add(nw[ii][jj+k],mul(mul(finv[k],d),t));
		}
	/*cout<<"vvvvv"<<endl;
	for(int ii=0;ii<=sn;++ii)
	{
		for(int jj=0;jj<=sm;++jj)
			cout<<nw[ii][jj]<<" ";
		cout<<endl;
	}
	cout<<"^^^^^"<<endl;*/
	int ans=0,lambda,f,d;
	for(int ii=0;ii<=sn;++ii)
		for(int jj=0;jj<=sm;++jj){
			lambda = nw[ii][jj];
			if(!lambda)	continue;
			f = mul(fact[jj+bi],finv[bi-1]);
			d = qp(mul(s,invs[s-ii]),jj+bi+1);
			//cout<<ii<<" "<<jj<<" "<<lambda<<" "<<f<<" "<<d<<endl;
			ans = add(ans, mul(lambda,mul(f,d)) );
		}
	return mul(ans,qp(p,bi));
}
inline void init(){
	fact[0]=invs[0]=1;
	for(int i=1;i<maxm;++i)
		fact[i]=mul(fact[i-1],i);
	finv[maxm-1]=qp(fact[maxm-1],mod-2);
	for(int i=maxm-2;i>=0;--i)
		finv[i]=mul(finv[i+1],i+1);
	for(int i=1;i<maxm-1;++i)
		invs[i]=mul(finv[i],fact[i-1]);
}
int main(){
    ios::sync_with_stdio(false);
    init();
    cin>>n;
    for(int i=0;i<n;++i)
		cin>>a[i]>>b[i];
	for(int i=0;i<n;++i)	s=add(s,a[i]);
	tran();
	int ans=0;
	for(int i=0;i<n;++i)
		ans = add(ans,get(a[i],b[i]));
	cout<<ans<<endl;
	return 0;
}