// Legends Never Die.

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef pair<int, int> pii;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline int chkmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline int chkmax(T &a, const T &b) { return b > a ? a = b, 1 : 0; }

template<typename T> inline T read()
{
	register T sum(0), fg(1);
	register char ch(getchar());
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getchar()) sum = sum * 10 - '0' + ch;
	return sum * fg;
}

const int MOD = 998244353;

inline int fpm(int x, int y)
{
	int res = 1;
	for(; y; y >>= 1, x = (LL) x * x % MOD) if(y & 1) res = (LL) res * x % MOD;
	return res;
}

inline int inv(int x) { assert(x != 0); return fpm(x, MOD - 2); }

const int MAXN = 400;

namespace MATH
{
	const int n = MAXN * 2;

	int fac[n + 5], ifac[n + 5];

	inline void init()
	{
		fac[0] = 1;
		for(int i = 1; i <= n; ++i) fac[i] = (LL) fac[i - 1] * i % MOD;
		ifac[n] = inv(fac[n]);
		for(int i = n - 1; i >= 0; --i) ifac[i] = (LL) ifac[i + 1] * (i + 1) % MOD;
	}
}
using MATH::fac;
using MATH::ifac;

namespace NTT
{
	const int MAX_LEN = 1 << 10;

	int rev[MAX_LEN], gn[MAX_LEN], len, dis, inv_len;

	inline void init(int L)
	{
		for(len = 1, dis = 0; len <= L; len <<= 1) ++dis;
		for(int i = 0; i < len; ++i) rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (dis - 1));

		gn[0] = 1;
		for(int G = fpm(3, (MOD - 1) / len), i = 1; i <= len; ++i) gn[i] = (LL) gn[i - 1] * G % MOD;
		inv_len = inv(len);
	}

	inline void DFT(int *x, int type)
	{
		for(int i = 0; i < len; ++i) if(i < rev[i]) swap(x[i], x[rev[i]]);
		for(int k = 2; k <= len; k <<= 1)
			for(int j = 0; j < len; j += k)
				for(int i = 0; i < k >> 1; ++i)
				{
					int X = x[i + j], Y = (LL) x[i + j + k / 2] * (type == +1 ? gn[len / k * i] : gn[len - len / k * i]) % MOD;
					x[i + j] = (X + Y) % MOD;
					x[i + j + k / 2] = (X - Y) % MOD;
				}
		if(type == -1) for(int i = 0; i < len; ++i) x[i] = (LL) x[i] * inv_len % MOD;
	}

	inline void mul(int *f, int N, int *g, int M, int *s)
	{
		if(N + M == 0) { s[0] = (LL) f[0] * g[0] % MOD; return; }

		static int F[MAX_LEN], G[MAX_LEN], S[MAX_LEN];

		init(N + M);
		for(int i = 0; i < len; ++i) F[i] = i <= N ? f[i] : 0;
		for(int i = 0; i < len; ++i) G[i] = i <= M ? g[i] : 0;
		DFT(F, +1);
		DFT(G, +1);
		for(int i = 0; i < len; ++i) S[i] = (LL) F[i] * G[i] % MOD;
		DFT(S, -1);
		for(int i = 0; i <= N + M; ++i) s[i] = S[i];
	}
}

int n;

int A[MAXN + 5], B[MAXN + 5];

inline void input()
{
	n = read<int>();
	for(int i = 1; i <= n; ++i) A[i] = read<int>(), B[i] = read<int>();
}

inline void solve()
{
	int SA = 0, SB = 0;
	for(int i = 1; i <= n; ++i) SA += A[i], SB += B[i];

	static int pw[MAXN + 5][MAXN + 5], ipw[MAXN + 5][MAXN + 5];

	for(int i = 1; i <= n; ++i)
	{
		pw[i][0] = ipw[i][0] = 1;
		for(int iA = inv(A[i]), j = 1; j <= SB; ++j)
		{
			pw[i][j] = (LL) pw[i][j - 1] * A[i] % MOD;
			ipw[i][j] = (LL) ipw[i][j - 1] * iA % MOD;
		}
	}

	static int f[MAXN + 5][MAXN + 5][MAXN + 5][2];

	f[0][0][0][0] = -1;
	for(int preA = A[1], preB = B[1], i = 1; i <= n; ++i, preA += A[i], preB += B[i])
		for(int j = 0; j <= preA; ++j) for(int k = 0; k <= preB; ++k) for(int t = 0; t < 2; ++t)
		{
			(f[i][j][k][t] += f[i - 1][j][k][t]) %= MOD;
			if(j >= A[i])
			{
				for(int q = 0; q < B[i] && q <= k; ++q) (f[i][j][k][t] += (LL) -pw[i][q] * ifac[q] % MOD * f[i - 1][j - A[i]][k - q][t] % MOD) %= MOD;
				if(k >= B[i] && t == 1) (f[i][j][k][t] += (LL) -pw[i][B[i]] * ifac[B[i] - 1] % MOD * f[i - 1][j - A[i]][k - B[i]][0] % MOD) %= MOD;
			}
		}

	int ans = 0;
	for(int i = 0; i <= SA; ++i) for(int j = 0; j <= SB; ++j) if(f[n][i][j][1])
		(ans += (LL) f[n][i][j][1] * j % MOD * fpm(inv(i), j + 1) % MOD * SA % MOD * fac[j - 1] % MOD) %= MOD;
	printf("%d\n", (ans + MOD) % MOD);
}

int main()
{
#ifdef K_ON // K-ON!
	freopen("E.in", "r", stdin);
	freopen("E.out", "w", stdout);
#endif

	MATH::init();
	input();
	solve();

	return 0;
}



Measured memory_bytes: 514432