#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll MOD = 998244353;
ll add(ll x, ll y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
	if (p == 0) return 1;
	if (p & 1) return mult(x, bin_pow(x, p - 1));
	return bin_pow(mult(x, x), p / 2);
}
ll Rev(ll x) {
	return bin_pow(x, MOD - 2);
}

const int N = 403;
ll rev[N];
ll f[N], rf[N];
int n;
int a[N], b[N];
ll dp[N][N][N];
ll A[N][N], B[N][N];
ll D[N][N];

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	rev[1] = 1;
	for (ll x = 2; x < N; x++)
		rev[x] = sub(0, mult(rev[MOD % x], MOD / x));
	f[0] = rf[0] = 1;
	for (int i = 1; i < N; i++) {
		f[i] = mult(f[i - 1], i);
		rf[i] = mult(rf[i - 1], rev[i]);
	}

	A[0][0] = 1;
	for (int i = 0; i < N - 3; i++) {
		for (int j = i + 1; j > 0; j--)
			A[i + 1][j] = sub(A[i][j - 1], mult(A[i][j], i));
		A[i + 1][0] = sub(0, mult(A[i][0], i));
	}
/*
	for (int i = 0; i < 5; i++) {
		for (int j = 0; j <= i; j++)
			eprintf("%lld ", A[i][j]);
		eprintf("\n");
	}
*/

	D[0][0] = 1;
	for (int d = 0; d < N - 3; d++) {
		for (int i = 0; i <= d; i++) {
			ll z = mult(D[d][i + 1], i + 1);
			D[d + 1][i + 1] = sub(D[d + 1][i + 1], z);
			D[d + 1][i] = add(D[d + 1][i], z);
		}
		for (int i = 0; i <= d; i++)
			D[d + 1][i] = add(D[d + 1][i], mult(D[d][i], d + 1));
		for (int i = d + 1; i > 0; i--)
			D[d + 1][i] = D[d + 1][i - 1];
		D[d + 1][0] = 0;
	}
/*
	for (int d = 0; d < 5; d++) {
		for (int i = 0; i <= d + 3; i++)
			eprintf("%lld ", D[d][i]);
		eprintf("\n");
	}
*/
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d%d", &a[i], &b[i]);
	dp[0][0][0] = 1;
	int SA = 0;
	for (int i = 0; i < n; i++)
		SA += a[i];
	ll Q = rev[SA];
	int curA = 0, curB = 0;
	for (int i = 0; i < n; i++) {
		for (int sum = 0; sum <= curB; sum++)
			for (int q = 0; q <= curA; q++) {
				if (dp[i][sum][q] == 0) continue;
				dp[i + 1][sum][q + a[i]] = add(dp[i + 1][sum][q + a[i]], dp[i][sum][q]);
				ll z = mult(a[i], Q);
				ll pw = 1;
				for (int x = 0; x < b[i]; x++) {
					dp[i + 1][sum + x][q] = sub(dp[i + 1][sum + x][q], mult(dp[i][sum][q], mult(rf[x], pw)));
					pw = mult(pw, z);
				}
			}

		curA += a[i];
		curB += b[i] - 1;
	}

	ll ans = 0;
	for (int sum = 0; sum <= curB; sum++)
		for (int q = 0; q <= curA; q++) {
			if (q == 0) {
				ll cur = mult(f[sum], dp[n][sum][q]);
				ans = add(ans, cur);
				continue;
			}
			ll z = mult(rev[q], curA);
			ll pp = bin_pow(z, sum);
			pp = mult(pp, dp[n][sum][q]);
			for (int i = 0; i <= sum; i++)
				B[q][i] = add(B[q][i], mult(pp, A[sum][i]));
		}
	for (int q = 1; q < curA; q++) {
		ll x = mult(q, rev[curA]);
		ll z = Rev(sub(1, x));
		for (int d = 0; d < N; d++) {
			ll w = B[q][d];
			if (w == 0) continue;
			ll cur = 0, pw = bin_pow(z, d + 1);
			for (int i = 0; i <= d; i++) {
				cur = add(cur, mult(pw, D[d][i]));
				pw = mult(pw, x);
			}
			ans = add(ans, mult(w, cur));
		}
	}
	ans = sub(0, ans);
	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 512256