#include <bits/stdc++.h>
using namespace std;

const int Maxn = 405, p = 998244353;
int S;
long long fac[Maxn], finv[Maxn];
long long fast_pow(long long x, long long y)
{
	long long ans = 1, now = x;
	while (y)
	{
		if (y & 1) ans = ans * now % p;
		now = now * now % p;
		y >>= 1;
	}
	return ans;
}
void init(void)
{
	fac[0] = 1;
	for (int i = 1; i <= 400; i++)
		fac[i] = fac[i - 1] * i % p;
	finv[400] = fast_pow(fac[400], p - 2);
	for (int i = 399; i >= 0; i--)
		finv[i] = finv[i + 1] * (i + 1) % p;
}
void multi(long long x[], long long y[], long long ans[], int len)
{
	for (int i = 0; i <= S; i++)
		for (int j = 0; i + j <= S && j < len; j++)
			(ans[i + j] += p - x[i] * y[j] % p) %= p;
}
void add(long long x[], long long ans[])
{
	for (int i = 0; i <= S; i++)
		(ans[i] += x[i]) %= p;
}
int n, a[Maxn], b[Maxn];
long long ans, invS, f[Maxn][Maxn], g[Maxn][Maxn], tmp[Maxn];
int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d%d", &a[i], &b[i]), S += a[i];
	init();
	invS = fast_pow(S, p - 2);
	f[0][0] = 1;
	for (int i = 1; i <= n; i++)
	{
		memcpy(g, f, sizeof(g));
		memset(f, 0, sizeof(f));
		tmp[0] = 1;
		for (int j = 1; j < b[i]; j++)
			tmp[j] = tmp[j - 1] * a[i] % p * invS % p;
		for (int j = 1; j < b[i]; j++)
			tmp[j] = tmp[j] * finv[j] % p;
		for (int j = 0; j <= S - a[i]; j++)
		{
			multi(g[j], tmp, f[j], b[i]);
			add(g[j], f[j + a[i]]);
		}
	}
	for (int d = 0; d < S; d++)
	{
		long long c = d * invS % p, L = 1 * fast_pow(1 - c + p, p - 2);
		(ans += L * f[d][0]) %= p;
		for (int i = 1; i <= S; i++)
		{
			L = fast_pow(1 - c + p, p - 2) % p * i % p * L % p;
			(ans += L * f[d][i]) %= p;
		}
	}
	printf("%lld", (p - ans) % p);
	return 0;
}