#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();
}
