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;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<int,int>
#define poly vector<ll>
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=405,mod=998244353;
int b[N],sa,sb,n;
ll a[N],A[N],fac[N],ni[N],dp[2][N][N],yc[N],xs[N][N],inv[N];
ll ksm(ll a,int b){
	int ans=1;
	for(;b;b>>=1){
		if(b&1)ans=ans*a%mod;
		a=a*a%mod;
	}
	return ans;
}
int main(){
	For(i,fac[0]=ni[0]=1,N-1){
		fac[i]=fac[i-1]*i%mod; ni[i]=ksm(fac[i],mod-2);
	}
	n=read(); ll s=0;
	For(i,1,n){s+=(a[i]=read());b[i]=read(); }
	inv[1]=1; For(i,2,n)inv[i]=mod-mod/i*inv[mod%i]%mod;
	s=ksm(s%mod,mod-2);
	For(i,1,n){
		A[i]=a[i]*s%mod;
	}
	dp[0][0][0]=1;
	For(i,1,n){
		int t=i&1,s=t^1;
		For(j,yc[0]=1,b[i]-1)yc[j]=yc[j-1]*A[i]%mod;
		For(j,0,b[i]-1)yc[j]=yc[j]*(mod-ni[j])%mod;
		sa+=a[i]; sb+=b[i]-1;
		For(j,0,sa)For(k,0,sb){
			dp[t][j][k]=j>=a[i]?dp[s][j-a[i]][k]:0;
			int meiju=min(k,b[i]-1);
			//cout<<meiju<<" "<<k<<" "<<i<<" "<<j<<endl;
			For(l,0,meiju)dp[t][j][k]=(dp[t][j][k]+dp[s][j][k-l]*yc[l])%mod;
		} 
	}
	//cout<<sa<<" "<<sb<<endl;
	For(i,0,sa-1){
		xs[i][0]=ksm((1-i*s)%mod,mod-2);
		For(j,1,sb){
			xs[i][j]=xs[i][j-1]*j%mod*xs[i][0]%mod;
			//wri(xs[i][j]); 
		}//puts("");
	}
	ll ans=0;
	//For(i,0,sa-1)For(j,0,sb)cout<<dp[n&1][i][j]<<" "<<i<<" "<<j<<endl;
	For(i,0,sa-1)For(j,0,sb)ans=(ans+xs[i][j]*dp[n&1][i][j])%mod;
	cout<<(-ans%mod+mod)%mod<<endl;
}