Problem: Consider a road consisting of several rows. Each row is divided into several rectangular tiles, and all tiles in the same row are equal. The first row contains exactly one rectangular tile. Look at the picture below which shows how the tiles are arranged.

The road is constructed as follows: 

  * the first row consists of 1 tile; 
  * then a_1 rows follow; each of these rows contains 1 tile greater than the previous row; 
  * then b_1 rows follow; each of these rows contains 1 tile less than the previous row; 
  * then a_2 rows follow; each of these rows contains 1 tile greater than the previous row; 
  * then b_2 rows follow; each of these rows contains 1 tile less than the previous row; 
  * ... 
  * then a_n rows follow; each of these rows contains 1 tile greater than the previous row; 
  * then b_n rows follow; each of these rows contains 1 tile less than the previous row. 

<image> An example of the road with n = 2, a_1 = 4, b_1 = 2, a_2 = 2, b_2 = 3. Rows are arranged from left to right. 

You start from the only tile in the first row and want to reach the last row (any tile of it). From your current tile, you can move to any tile in the next row which touches your current tile.

Calculate the number of different paths from the first row to the last row. Since it can be large, print it modulo 998244353.

Input

The first line contains one integer n (1 ≤ n ≤ 1000).

Then n lines follow. The i-th of them contains two integers a_i and b_i (1 ≤ a_i, b_i ≤ 10^5; |a_i - b_i| ≤ 5).

Additional constraint on the input: the sequence of a_i and b_i never results in a row with non-positive number of tiles.

Output

Print one integer — the number of paths from the first row to the last row, taken modulo 998244353.

Examples

Input


2
4 2
2 3


Output


850


Input


3
4 1
2 3
3 1


Output


10150


Input


8
328 323
867 868
715 718
721 722
439 435
868 870
834 834
797 796


Output


759099319

Solution (in CPP):

Solution:
#include <bits/stdc++.h>

using namespace std;

#ifdef NeverBeRed
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ld> point;
#define F first
#define S second

template<typename T, typename U>
T pow_mod(T a, U b, int mod)
{
	T r = 1;
	for (; b > 0; b >>= 1)
	{
		if (b & 1) r = (ll)r * a % mod;
		a = (ll)a * a % mod;
	}
	return r;
}

namespace ntt
{
	const int mod = 998244353;
	const int root = 5;

	int base = 1;
	vector<int> roots;

	void ensure_base(int nbase)
	{
		if (nbase <= base) return;
		roots.resize(nbase);
		for (int mh = base; mh << 1 <= nbase; mh <<= 1)
		{
			int wm = pow_mod(root, (mod - 1) / (mh << 1), mod);
			roots[mh] = 1;
			for (int i = 1; i < mh; ++i)
				roots[i + mh] = (ll)roots[i + mh - 1] * wm % mod;
		}
		base = nbase;
	}

	void fft(int a[], int n, int sign)
	{
		ensure_base(n);

		for (int i = 1, j = 0; i < n - 1; ++i)
		{
			for (int k = n >> 1; (j ^= k) < k; k >>= 1);
			if (i < j) swap(a[i], a[j]);
		}

		for (int m, mh = 1; (m = mh << 1) <= n; mh = m)
			for (int i = 0; i < n; i += m)
				for (int j = i; j < i + mh; ++j)
				{
					int y = (ll)a[j + mh] * roots[j - i + mh] % mod;
					if ((a[j + mh] = a[j] - y) < 0) a[j + mh] += mod;
					if ((a[j] += y) >= mod) a[j] -= mod;
				}

		if (sign < 0)
		{
			int inv = pow_mod(n, mod - 2, mod);
			for (int i = 0; i < n; ++i) a[i] = (ll)a[i] * inv % mod;
			reverse(a + 1, a + n);
		}
	}

	vector<int> convolve(vector<int> x, vector<int> y)
	{
		int n = x.size() + y.size() - 1, sz = 1;
		while (sz < n) sz <<= 1;
		x.resize(sz);
		y.resize(sz);
		fft(x.data(), sz, +1);
		fft(y.data(), sz, +1);
		for (int i = 0; i < sz; ++i)
			x[i] = (ll)x[i] * y[i] % mod;
		fft(x.data(), sz, -1);
		x.resize(n);
		return x;
	}
}

namespace combinatorics
{
	const int mod = 998244353, N = 2e5+5;
	int fac[N], ifac[N];

	void init()
	{
		fac[0] = ifac[0] = 1;
		for (int i = 1; i < N; ++i)
		{
			fac[i] = (ll)fac[i-1] * i % mod;
			ifac[i] = pow_mod(fac[i], mod-2, mod);
		}
	}

	int comb(int n, int k)
	{
		if (k < 0 || k > n) return 0;
		return (ll)fac[n] * ifac[n-k] % mod * ifac[k] % mod;
	}
}

using namespace combinatorics;

int main()
{
	#ifdef TurnRed
		//freopen("a.in", "r", stdin);
		//freopen("a.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	init();

	int n;
	cin >> n;

	vector<int> p = { 1 };
	for (int a, b; n--; )
	{
		cin >> a >> b;

		int sz = p.size();
		vector<int> q(2 * sz + a - b);
		for (size_t i = 0; i < q.size(); ++i)
			q[i] = comb(a + b, b + i - sz);

		p = ntt::convolve(p, q);
		p.erase(p.begin(), p.begin() + sz);
		p.resize(sz + a - b);
	}

	int ans = 0;
	for (auto i : p)
		ans = (ans + i) % ntt::mod;
	cout << ans << "\n";

	return 0;
}