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 <cstring>
using namespace std ;
const int N = 400,M = N+10,mod = 998244353 ;
inline int add(int a,int b){ return a+b >= mod ? a+b-mod : a+b ; }
inline int sub(int a,int b){ return a >= b ? a-b : a-b+mod ; }
inline int mul(int a,int b){ return 1ll*a*b%mod ; }
inline int power(int a,int b){
    int res = 1 ;
    for( ; b ; b >>= 1){
        if(b&1) res = mul(res,a) ;
        a = mul(a,a) ; 
    }
    return res ; 
}
int fac[M],inv[M],S ; 
inline void prework(void){
    fac[0] = inv[0] = 1 ;
    for(int i = 1 ; i <= N ; i++) fac[i] = mul(fac[i-1],i) ;
    for(int i = 1 ; i <= N ; i++) inv[i] = power(fac[i],mod-2) ;
}
inline void Mul(int *a,int *b,int *c,int len){
    for(int i = 0 ; i <= S ; i++)
        for(int j = 0 ; i+j <= S && j < len ; j++)
           c[i+j] = add(c[i+j],sub(mod,mul(a[i],b[j]))) ; 
}
inline void Plus(int *a,int *b){
    for(int i = 0 ; i <= S ; i++) b[i] = add(b[i],a[i]) ;
}
int n,a[M],b[M],c[M],f[M][M],g[M][M],Inv,ans ; 
int main(){
    //freopen("in.txt","r",stdin) ; 
    prework() ; 
    cin >> n ;
    for(int i = 1 ; i <= n ; i++) scanf("%d%d",&a[i],&b[i]),S += a[i] ;
    Inv = power(S,mod-2) ; f[0][0] = 1 ;
    for(int i = 1 ; i <= n ; i++){
        memcpy(g,f,sizeof g) ;
        memset(f,0,sizeof f) ;
        c[0] = 1 ; 
        for(int j = 1 ; j < b[i] ; j++)
            c[j] = mul(c[j-1],mul(a[i],Inv)) ; 
        for(int j = 1 ; j < b[i] ; j++)
            c[j] = mul(c[j],inv[j]) ;
        for(int j = 0 ; j <= S-a[i] ; j++)
            Mul(g[j],c,f[j],b[i]),Plus(g[j],f[j+a[i]]) ; 
    }
    for(int d = 0 ; d < S ; d++){
        int e = mul(d,Inv),L = power(sub(1,e),mod-2) ;
        ans = add(ans,mul(L,f[d][0])) ;
        for(int i = 1 ; i <= S ; i++){
            L = mul(power(sub(1,e),mod-2),mul(i,L)) ;
            ans = add(ans,mul(L,f[d][i])) ; 
        }
    }
    cout << sub(mod,ans) << endl ; 
    return 0 ; 
}