#include <iostream>

using i64 = long long;

const i64 MOD = 998244353;
const int N = 400 + 7;

i64 inv[N];
int n, p[N], c[N], sp;
i64 f[N][N], g[N], ans;

int main() {
//	freopen("code.in", "r", stdin);
//	freopen("code.out", "w", stdout);

	inv[1] = 1;
	for (int i = 2; i <= 400; ++i)
		inv[i] = -MOD / i * inv[MOD % i] % MOD;

	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
		scanf("%d%d", p + i, c + i), sp += p[i];
	c[0] = f[0][0] = 1;
	for (int i = 1; i <= n; ++i) {
		for (int v = g[0] = 1; v < c[i]; ++v)
			g[v] = g[v - 1] * p[i] % MOD * inv[sp] % MOD * inv[v] % MOD;
		for (int j = p[0]; ~j; --j)
			for (int u = 0; u < c[0]; ++u)
				for (int v = 0; v < c[i]; ++v)
					( f[j + p[i]][u + v] -= f[j][u] * g[v] ) %= MOD;
		p[0] += p[i], c[0] += c[i];
	}
	for (int i = 1; i <= p[0]; ++i) {
		g[0] = sp * inv[i] % MOD;
		for (int j = 1; j < c[0]; ++j)
			g[j] = g[j - 1] * j % MOD * sp % MOD * inv[i] % MOD;
		for (int j = 0; j < c[0]; ++j)
			( ans -= f[i][j] * g[j] ) %= MOD;
	}
	printf("%lld\n", (ans + MOD) % MOD);

	return 0;
}
