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;
namespace mine
{
    typedef long long ll;
    #define pr pair<int,int>
    #define FR first
    #define SE second
    #define MP make_pair
    #define PB push_back
    #define vc vector
    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())
    #define bin(x) (1ll<<(x))
    #define GG(x) if(x) puts("error")
    #define rep(i,l,r) for(int i=(l);i<=(r);i++)
    ll qread()
    {
        ll ans=0,f=1;char c=getchar();
        while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
        while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
        return ans*f;
    }
    void write(ll num)
    {
        if(num<0) putchar('-'),num=-num;
        if(num>=10) write(num/10);
        putchar('0'+num%10);
    }
    void write1(ll num){write(num);putchar(' ');}
    void write2(ll num){write(num);putchar('\n');}
    template<typename T> void chmax(T &x,const T y) {x=(x>y?x:y);}
    template<typename T> void chmin(T &x,const T y) {x=(x<y?x:y);}
    ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

    const int INF=0x3f3f3f3f;
    const int MOD=998244353;
    inline int mm(const int x){return x>=MOD?x-MOD:x;}
    template<typename T> inline void add(T &x,const T y){x=mm(x+y);}
    inline ll qpower(ll x,ll e)
    {
        ll ans=1;GG(e<0);
        while(e){if(e&1)ans=ans*x%MOD;x=x*x%MOD;e>>=1;}return ans;
    }
    ll invm(ll x){return qpower(x,MOD-2);}
    const int N=400+10;

    ll fac[N],facinv[N];
    ll f[N][N];ll a[N][N],b[N],aa[N];
    void main()
    {
        fac[0]=1;for(int i=1;i<N;i++) fac[i]=fac[i-1]*i%MOD;
        facinv[N-1]=invm(fac[N-1]);for(int i=N-2;i>=0;i--) facinv[i]=facinv[i+1]*(i+1)%MOD;

        int n=qread(),Sa=0,Sb=0;
        for(int i=1;i<=n;i++) aa[i]=qread(),Sa+=aa[i],b[i]=qread(),Sb+=b[i];
        for(int i=1;i<=n;i++)
        {
            a[i][0]=1;a[i][1]=aa[i];
            for(int t=2;t<N;t++) a[i][t]=a[i][t-1]*a[i][1]%MOD;
        }

        f[0][0]=MOD-1;
        for(int i=1;i<=n;i++) for(int sa=Sa;sa>=0;sa--) for(int sb=Sb;sb>=0;sb--) if(f[sa][sb])
            for(int ad=0;ad<b[i];ad++) add(f[sa+aa[i]][sb+ad],MOD-f[sa][sb]*a[i][ad]%MOD*facinv[ad]%MOD );
        ll ans=0;
        for(int sa=1;sa<=Sa;sa++) for(int sb=0;sb<=Sb;sb++)
            add(ans, f[sa][sb]*fac[sb]%MOD*Sa%MOD*invm( qpower(sa,sb)*sa%MOD )%MOD );
        write(ans);
    }
};//(ans+MOD)%MOD
int main()
{
    srand(time(0));
    mine::main();
}