#include<bits/stdc++.h>
#define p 998244353
#define ll long long
using namespace std;

int A[410],B[410],f[410][410][410],fac[410],inv[410];

inline ll read()
{
	ll ans=0,f=1;char c=getchar();
	while(c>'9'||c<'0') {if(c=='-') f=-1;c=getchar();}
	while(c>='0'&&c<='9') ans=(ans<<1)+(ans<<3)+(c^48),c=getchar();
	return ans*f;
}

int mul(int a,int b)
{
	int ans=1;
	while(b)
	{
		if(b&1)ans=1ll*ans*a%p;
		a=1ll*a*a%p;b>>=1;
	}
	return ans;
}

inline void add(int &x,int y){x=(x+y<p)?x+y:x+y-p;}

int main(){
	int n=read(),SA=0,S=0;
	for(int i=1;i<=n;++i)SA+=A[i]=read(),S+=B[i]=read();
	fac[0]=1;for(int i=1;i<=S;++i)fac[i]=1ll*fac[i-1]*i%p;
	inv[S]=mul(fac[S],p-2);
	for(int i=S;i;--i)inv[i-1]=1ll*inv[i]*i%p;
	f[1][0][0]=p-1;
	for(int i=1;i<=n;++i)
		for(int j=0;j<=SA;++j)
			for(int k=0;k<=S;++k)
			{
				if(!f[i][j][k])continue;
				add(f[i+1][j][k],f[i][j][k]);
				for(int l=0,x=1;l<B[i];++l,x=1ll*x*A[i]%p)
					add(f[i+1][j+A[i]][k+l],p-1ll*f[i][j][k]*x%p*inv[l]%p);
			}
	int ans=0;
	for(int i=0;i<=SA;++i)
		for(int j=0;j<=S;++j)
			add(ans,1ll*f[n+1][i][j]*mul(i,p-j-2)%p*fac[j]%p*SA%p);
	printf("%d",ans);
	return 0;
}
