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<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<cstdlib>
#define LL long long
#define LD long double
using namespace std;
const int NN=300 +117;
const int MM= +117;
int read(){
	int fl=1,x;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if(c=='-'){fl=-1;c=getchar();}
	for(x=0;c>='0'&&c<='9';c=getchar())
		x=(x<<3)+(x<<1)+c-'0';
	return x*fl;
}
void open(){
	freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
}
void close(){
	fclose(stdin);
	fclose(stdout);
}


int m,n;
LL dp[2][NN][NN]={};
LL a[NN]={};
LL b[NN]={};
LL fact[NN]={};
LL rev[NN]={};
const int mod=998244353;
LL ksm(LL a,LL b){
	LL ret=1;
	for(;b;b>>=1,a=a*a%mod){
		if(b&1)ret=ret*a%mod;
	}
	return ret;
}
void getfact(int n){
	fact[0]=1;
	for(int i=1;i<=n;++i)fact[i]=fact[i-1]*i%mod;
	rev[n]=ksm(fact[n],mod-2);
	for(int i=n;i>=1;--i)rev[i-1]=rev[i]*i%mod;
}
void upd(LL &a,LL b){
	a=(a+b)%mod;
}
int main(){
	//open();
	n=read();
	int s=0;
	for(int i=1;i<=n;++i){
		a[i]=read();
		b[i]=read();
		s+=b[i];
	}
	getfact(s);
	int now=0;
	dp[now][0][0]=-1;
	int suma=0,sumb=0;
	for(int x=1;x<=n;++x){
		now^=1;
		for(int i=0;i<=suma+a[x];++i){
			for(int j=0;j<=sumb+b[x];++j){
				dp[now][i][j]=0;
			}
		}
		for(int i=0;i<=suma;++i){
			for(int j=0;j<=sumb;++j){
				upd(dp[now][i][j],dp[now^1][i][j]);
				LL mi=1;
				for(int k=0;k<b[x];++k,mi=mi*a[x]%mod){
					upd(dp[now][i+a[x]][j+k],-dp[now^1][i][j]*rev[k]%mod*mi);
				}
			}
		}
		suma+=a[x],sumb+=b[x];
	}
	LL ans=0;
	for(int i=1;i<=suma;++i){
		LL di=ksm(i,mod-2);
		LL mi=di;
		for(int j=0;j<=sumb;++j,mi=mi*di%mod){
			ans+=dp[now][i][j]*mi%mod*suma%mod*fact[j];
			ans%=mod;
		}
	}
	ans=(ans+mod)%mod;
	printf("%lld\n",ans);
	close();
	return 0;
}