// Author -- Frame

#include<bits/stdc++.h>

#define lowbit(x) ((x)&(-(x)))
#define Finline __inline__ __attribute__ ((always_inline))
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
#define SZ(x) ((int)x.size())
#define mkpr std::make_pair
#define pb push_back

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef std::pair<int,int> pi;
typedef std::pair<ll,ll> pl;

const int inf=0x3f3f3f3f,Inf=0x7fffffff;
const ll INF=0x3f3f3f3f3f3f3f3f;

Finline uint rnd(){static uint seed=416;return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;}
template <typename _Tp>_Tp gcd(const _Tp &a,const _Tp &b){return (!b)?a:gcd(b,a%b);}
template <typename _Tp>Finline _Tp abs(const _Tp &a){return a>=0?a:-a;}
template <typename _Tp>Finline _Tp max(const _Tp &a,const _Tp &b){return a<b?b:a;}
template <typename _Tp>Finline _Tp min(const _Tp &a,const _Tp &b){return a<b?a:b;}
template <typename _Tp>Finline void chmax(_Tp &a,const _Tp &b){(a<b)&&(a=b);}
template <typename _Tp>Finline void chmin(_Tp &a,const _Tp &b){(b<a)&&(a=b);}
template <typename _Tp>Finline void read(_Tp &x)
{
	char ch(getchar());bool f(false);while(!isdigit(ch)) f|=ch==45,ch=getchar();
	x=ch&15,ch=getchar();while(isdigit(ch)) x=(((x<<2)+x)<<1)+(ch&15),ch=getchar();
	f&&(x=-x);
}
template <typename _Tp,typename... Args>Finline void read(_Tp &t,Args &...args){read(t);read(args...);}
template <typename _Tp,typename... Args>Finline _Tp min(const _Tp &a,const _Tp &b,const Args &...args){return a<b?min(a,args...):min(b,args...);}
template <typename _Tp,typename... Args>Finline _Tp max(const _Tp &a,const _Tp &b,const Args &...args){return a<b?max(b,args...):max(a,args...);}
Finline int read_str(char *s)
{
	char ch(getchar());while(ch==' '||ch=='\r'||ch=='\n') ch=getchar();
	char *tar=s;*tar=ch,ch=getchar();while(ch!=' '&&ch!='\r'&&ch!='\n'&&ch!=EOF) *(++tar)=ch,ch=getchar();
	return tar-s+1;
}

const int N=405;
const int mod=998244353;
template<typename _Tp1,typename _Tp2>Finline void add(_Tp1 &a,_Tp2 b){(a+=b)>=mod&&(a-=mod);}
template<typename _Tp1,typename _Tp2>Finline void sub(_Tp1 &a,_Tp2 b){(a-=b)<0&&(a+=mod);}
ll ksm(ll a,ll b=mod-2)
{
	ll res=1;
	while(b)
	{
		if(b&1) res=res*a%mod;
		a=a*a%mod,b>>=1;
	}
	return res;
}
int a[N],b[N];
int dp[N][N][2];
ll fac[N],inv[N],ifac[N];
ll pw[N][N],_[N][N];
int main()
{
	fac[0]=fac[1]=inv[0]=inv[1]=ifac[0]=ifac[1]=1;
	for(int j=0;j<N;++j) _[0][j]=_[1][j]=1;
	for(int i=2;i<N;++i)
	{
		fac[i]=fac[i-1]*i%mod,inv[i]=inv[mod%i]*(mod-mod/i)%mod,ifac[i]=ifac[i-1]*inv[i]%mod;
		_[i][0]=1;for(int j=1;j<N;++j) _[i][j]=_[i][j-1]*inv[i]%mod;
	}
	int n;read(n);
	int qwq=0;
	for(int i=1;i<=n;++i) read(a[i],b[i]),qwq+=a[i];
	for(int i=1;i<=n;++i)
	{
		pw[i][0]=1;
		for(int j=1;j<=b[i];++j) pw[i][j]=pw[i][j-1]*a[i]%mod;
	}
	int sum=0,qaq=0;
	dp[0][0][0]=mod-1;
	for(int i=1;i<=n;++i)
	{
		for(int j=sum;j>=0;--j)
		{
			for(int p=qaq;p>=0;--p)
			{
				sub(dp[j+(b[i]-1)][p+a[i]][1],1ll*dp[j][p][0]*ifac[b[i]-1]%mod*pw[i][b[i]]%mod);
				for(int k=b[i]-1;k>=0;--k) for(int t=0;t<2;++t)	sub(dp[j+k][p+a[i]][t],1ll*dp[j][p][t]*pw[i][k]%mod*ifac[k]%mod);
			}
		}
		sum+=b[i]-1,qaq+=a[i];
	}
	int ans=0;
	for(int j=0;j<=sum;++j) for(int k=0;k<=qaq;++k)	add(ans,1ll*fac[j]*_[k][j+2]%mod*(j+1)%mod*dp[j][k][1]%mod);
	printf("%lld\n",1ll*ans*qwq%mod);
	return 0;
}


Measured memory_bytes: 6336