#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define fi first
#define se second
using namespace std;

typedef long long LL;
typedef pair <int, int> P;
const int inf = 0x3f3f3f3f, N = 5005, mod = 998244353, M = 6e5 + 10;
template <typename T>
void rd_(T &x) {
	x = 0; int f = 1;
	char ch = getchar();
	for (; ch > '9' || ch < '0'; ch = getchar()) if (ch == '-') f = -1;
	for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x*10 + ch - '0';
	x *= f;
}

LL fpow_(LL a, LL b, LL res = 1) {
	for (; b; b >>= 1, a = a*a%mod)
		if (b&1) res = res*a%mod;
	return res;
}

int n, a, b, f[M], g[M], len, tr[M], tot, tk, R = 3, iR = fpow_(3, mod - 2);
LL fac[M], inv[M], ans; 

void init_(int n) {
	fac[0] = inv[0] = 1;
	rep (i, 1, n) fac[i] = fac[i - 1]*i%mod;
	inv[n] = fpow_(fac[n], mod - 2);
	per (i, n - 1, 1) inv[i] = inv[i + 1]*(i + 1)%mod;
}

void ntt_(int *a, int f = 1) {
	rep (i, 0, len - 1)
		if (i < tr[i]) swap(a[i], a[tr[i]]);
	for (int l = 2; l <= len; l <<= 1) {
		int wn = fpow_(f == 1 ? R : iR, (mod - 1)/l);
		for (int j = 0; j < len; j += l) {
			int w = 1;
			for (int k = 0; k < l/2; k++) {
				int u = a[j + k], v = 1ll*a[j + k + l/2]*w%mod;
				a[j + k] = (u + v)%mod, a[j + k + l/2] = (u - v + mod)%mod;
				w = 1ll*w*wn%mod;
			}
		}
	}
	if (f == -1) {
		int iL = fpow_(len, mod - 2);
		rep (i, 0, len - 1)
			a[i] = 1ll*a[i]*iL%mod;
	}
}

int main() {
	rd_(n), init_(600000);
	f[0] = 1, tot = 0;
	rep (T, 1, n) {
		rd_(a), rd_(b);
		for (len = 1, tk = 0; len <= 3*tot + a - b; len <<= 1) tk++;
		rep (i, 0, len - 1) {
			tr[i] = (tr[i>>1]>>1) | ((i&1)<<tk - 1);
			g[i] = 0;
		}
		rep (i, 0, tot + tot + a - b)
			if (b + (i - tot) >= 0 && a - (i - tot) >= 0) 
				g[i] = inv[b + (i - tot)]*inv[a - (i - tot)]%mod;
		rep (i, tot + 1, len - 1) f[i] = 0;
		ntt_(f), ntt_(g);
		rep (i, 0, len - 1) f[i] = 1ll*f[i]*g[i]%mod;
		ntt_(f, -1);
		rep (i, 0, tot + a - b)
			f[i] = f[i + tot]*fac[a + b]%mod;
		tot += a - b;
	}
	rep (i, 0, tot)
		ans = (ans + f[i])%mod;
	printf("%lld\n", ans);
}