// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

#define ll long long

#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)

#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)

#define EREP(i,u) for(int i=start[u];i;i=e[i].next)

#define fi first

#define se second

#define mkr(a,b) make_pair(a,b)

#define SZ(A) ((int)A.size())

template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}

template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}

inline int read()

{

	int s=0,f=1;char ch=getchar();

	while(!isdigit(ch) && ch!='-')ch=getchar();

	if(ch=='-')ch=getchar(),f=-1;

	while(isdigit(ch))s=s*10+ch-'0',ch=getchar();

	return ~f?s:-s;

}



const int maxn=420;

const int mod=998244353;

inline int power(int a,int b)

{

	int ans=1;

	while(b)

	{

		if(b&1)ans=(ll)ans*a%mod;

		b>>=1;

		a=(ll)a*a%mod;

	}

	return ans;

}



int jc[maxn],jcn[maxn],inv[maxn];

inline void prepare()

{

	jc[0]=jc[1]=jcn[0]=jcn[1]=inv[1]=1;

	REP(i,2,400)jc[i]=(ll)i*jc[i-1]%mod,inv[i]=(ll)(mod-mod/i)*inv[mod%i]%mod,jcn[i]=(ll)jcn[i-1]*inv[i]%mod;

}



int n,a[maxn],b[maxn],sa,sainv,p[maxn];



inline void init()

{

	n=read();

	REP(i,1,n)a[i]=read(),b[i]=read(),sa+=a[i];

	sainv=power(sa,mod-2);

	REP(i,1,n)p[i]=(ll)a[i]*sainv%mod;

}



int dp[maxn][maxn];



inline void doing()

{

	dp[0][0]=1;

	REP(i,1,n)

	{

		DREP(j,400,0)DREP(k,400,0)if(dp[j][k])

		{

			int t=dp[j][k]; dp[j][k]=0;

			int xs=1;

			dp[j][k+a[i]]=(dp[j][k+a[i]]+t)%mod;

			REP(x,0,b[i]-1)

			{

				dp[j+x][k]=(dp[j+x][k]-(ll)t*xs%mod+mod)%mod;

				xs=(ll)xs*p[i]%mod*inv[x+1]%mod;

			}

		}

	}

	int ans=0;

	REP(j,0,400)REP(k,0,sa-1)if(dp[j][k])

	{

		int v=(ll)k*sainv%mod;

		int c=(mod-dp[j][k])%mod;

		ans=(ans+(ll)c*power(1-v+mod,mod-j-2)%mod*jc[j])%mod;

	}

	printf("%d\n",ans);

}



int main()

{

	prepare();

	init();

	doing();

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 2.2016227224262592x):
#include<bits/stdc++.h>

#define LL long long

#define uLL unsigned long long



using namespace std;

const int N=400+10,mod=998244353;

int rd()

{

    int x=0,w=1;char ch=0;

    while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}

    while(ch>='0'&&ch<='9'){x=x*10+(ch^48);ch=getchar();}

    return x*w;

}

void ad(int &x,int y){x+=y,x-=x>=mod?mod:0;}

int fpow(int a,int b){int an=1;while(b){if(b&1) an=1ll*an*a%mod;a=1ll*a*a%mod,b>>=1;}return an;}

int ginv(int a){return fpow(a,mod-2);}

int n,a,pw[N],b,sa,sb,f[2][N][N],fac[N],iac[N];



int main()

{

	fac[0]=1;

	for(int i=1;i<=N-5;++i) fac[i]=1ll*fac[i-1]*i%mod;

	iac[N-5]=ginv(fac[N-5]);

	for(int i=N-5;i;--i) iac[i-1]=1ll*iac[i]*i%mod;

	n=rd();

	int nw=1,la=0;

	f[la][0][0]=mod-1;

	for(int i=1;i<=n;++i)

	{

		a=rd(),b=rd();

		pw[0]=1;

		for(int j=1;j<b;++j) pw[j]=1ll*pw[j-1]*a%mod;

		for(int j=0;j<=sa;++j)

			for(int k=0;k<=sb;++k)

			{

				if(!f[la][j][k]) continue;

				ad(f[nw][j][k],f[la][j][k]);

				for(int l=0;l<b;++l)

					ad(f[nw][j+a][k+l],mod-1ll*f[la][j][k]*pw[l]%mod*iac[l]%mod);

				f[la][j][k]=0;

			}

		nw^=1,la^=1;

		sa+=a,sb+=b-1;

	}

	int ans=0;

	for(int j=0;j<=sa;++j)

	{

		int w=ginv(j);

		for(int k=0,p=w;k<=sb;++k,p=1ll*p*w%mod)

			ad(ans,1ll*f[la][j][k]*p%mod*fac[k]%mod);

	}

	ans=1ll*ans*sa%mod;

	printf("%d\n",ans);

	return 0;

}