#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int mod=998244353;
#define N 432
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,a[N],b[N],dp[N][N][N],sumA,sumB,fac[N],inv[N],ans;
int qpow(int a,int b){
	int ans=1;
	while(b){
		if(b&1)ans=1LL*ans*a%mod;
		a=1LL*a*a%mod;
		b>>=1;
	}
	return ans;
}
void init(int n){
	fac[0]=1;
	for(int i=1;i<=n;++i){
		fac[i]=1LL*fac[i-1]*i%mod;
	}
	inv[n]=qpow(fac[n],mod-2);
	for(int i=n-1;i>=0;--i){
		inv[i]=1LL*inv[i+1]*(i+1)%mod;
	}
}
int main(){
	n=read();
	for(int i=1;i<=n;++i){
		a[i]=read(),b[i]=read();
	}
	init(400);
	dp[0][0][0]=-1;
	for(int i=1;i<=n;++i){
		sumA+=a[i];
		sumB+=b[i];
		memcpy(dp[i],dp[i-1],sizeof(dp[i]));
		for(int j=sumA;j>=a[i];--j){
			for(int k=0;k<=sumB;++k){
				for(int p=0,tmp=1;p<=min(b[i]-1,k);++p,tmp=1LL*tmp*a[i]%mod){
					dp[i][j][k]=(dp[i][j][k]-1LL*dp[i-1][j-a[i]][k-p]*tmp%mod*inv[p])%mod;
				}
			}
		}
	}
	for(int j=0;j<=sumA;++j){
		for(int k=0;k<=sumB;++k){
			ans=(ans+1LL*sumA*dp[n][j][k]%mod*fac[k]%mod*qpow(qpow(j,k+1),mod-2))%mod;
		}
	}
	printf("%d\n",(ans+mod)%mod);
	return 0;
}

