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



using namespace std;



namespace jumpmelon

{

	typedef long long big;



	const int P = 998244353;



	vector<int> operator*(const vector<int> &A, const vector<int> &B)

	{

		int n = (int)A.size(), m = (int)B.size();

		vector<int> R(n + m - 1);

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

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

				R[i + j] = int((R[i + j] + (big)A[i] * B[j]) % P);

		return R;

	}



	vector<int> operator+(const vector<int> &A, const vector<int> &B)

	{

		int n = (int)A.size(), m = (int)B.size();

		vector<int> R(max(n, m));

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

			R[i] = A[i];

		for (int i = 0; i < m; i++)

			R[i] = (R[i] + B[i]) % P;

		return R;

	}



	int inv(int x) { return x == 1 ? 1 : int(big(P - P / x) * inv(P % x) % P); }



	const int MAXN = 400;

	int A[MAXN], B[MAXN];

	int Fac[MAXN + 1], InvFac[MAXN + 1];

	int S[MAXN + 1][MAXN + 1];

	int L[MAXN + 1];

	vector<int> G[MAXN + 1];



	int C(int n, int m) { return int((big)Fac[n] * InvFac[m] % P * InvFac[n - m] % P); }



	void work()

	{

		int n, s = 0;

		scanf("%d", &n);

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

		{

			scanf("%d%d", &A[i], &B[i]);

			s += A[i];

		}

		Fac[0] = 1;

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

			Fac[i] = int((big)Fac[i - 1] * i % P);

		InvFac[MAXN] = inv(Fac[MAXN]);

		for (int i = MAXN; i >= 1; i--)

			InvFac[i - 1] = int((big)InvFac[i] * i % P);

		G[0] = {1};

		int inv_s = inv(s);

		for (int i = 0, t = 0; i < n; i++)

		{

			int c = int((big)A[i] * inv_s % P);

			vector<int> V(B[i]);

			for (int j = 0, v = 1; j < B[i]; j++, v = int((big)v * c % P))

				V[j] = int(big(P - v) * InvFac[j] % P);

			t += A[i];

			for (int j = t; j >= 0; j--)

			{

				if (!G[j].empty())

					G[j] = G[j] * V;

				if (j >= A[i])

					G[j] = G[j] + G[j - A[i]];

			}

		}

		S[0][0] = 1;

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

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

				S[i][j] = int((S[i - 1][j - 1] + big(i - 1) * S[i - 1][j]) % P);

		int ans = 0;

		for (int k = 0; k < (int)G[0].size(); k++)

			ans = int((ans + (big)G[0][k] * Fac[k]) % P);

		for (int d = 1; d < s; d++)

		{

			int c = int((big)d * inv_s % P), inv_c = inv(c);

			int vr = inv((1 + P - c) % P), vv = int((big)c * vr % P);

			L[0] = vr;

			for (int i = 1; i < (int)G[d].size(); i++)

			{

				L[i] = 0;

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

					L[i] = int((L[i] + (big)vv * C(i, j) % P * L[j]) % P);

			}

			for (int k = 0, v = 1; k < (int)G[d].size(); k++, v = int((big)v * inv_c % P))

				for (int i = k, u = 1; i >= 0; i--, u = P - u)

					ans = int(

						(ans + (big)G[d][k] * v % P * S[k][i] % P * u % P * L[i]) % P);

		}

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

	}

}



int main()

{

	jumpmelon::work();

	return 0;

}

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

using namespace std;

typedef long long ll;

typedef pair<int,int> PII;

const int maxn=444,mod=998244353;

#define MP make_pair

#define PB push_back

#define lson o<<1,l,mid

#define rson o<<1|1,mid+1,r

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

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

#define MEM(x,v) memset(x,v,sizeof(x))

inline ll read(){

	char ch=getchar();ll x=0,f=0;

	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();

	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();

	return f?-x:x;

}

inline int qmo(int x){return x+(x>>31?mod:0);}

int n,a[maxn],b[maxn],as,bs,f[maxn][maxn],C[maxn][maxn],ans;

inline int qpow(int a,int b){

	int ans=1;

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

	return ans;

}

int main(){

	n=read();

	FOR(i,1,n) as+=a[i]=read(),bs+=b[i]=read();

	FOR(i,0,bs) C[i][0]=C[i][i]=1;

	FOR(i,1,bs) FOR(j,1,i-1) C[i][j]=qmo(C[i-1][j]+C[i-1][j-1]-mod);

	f[0][0]=1;

	int asinv=qpow(as,mod-2);

	FOR(i,1,n) ROF(j,as,a[i]) ROF(k,bs,0){

		int pr=1,fac=1ll*a[i]*asinv%mod;

		FOR(t,0,min(b[i]-1,k)){

			f[j][k]=qmo(f[j][k]-1ll*f[j-a[i]][k-t]*C[k][t]%mod*pr%mod);

			pr=1ll*pr*fac%mod;

		}

	}

	FOR(j,0,as) FOR(k,0,bs) ans=qmo(ans+1ll*f[j][k]*qpow(1ll*as*qpow(j,mod-2)%mod,k+1)%mod-mod);

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

}