using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); public static void Main() { Solve(); } static void Solve() { var n = NN; var map = NArr(n); var mod = 998_244_353; var ans = 1L; var len = map[0][1] - map[0][0] + 1L; for (var i = 1; i < n; ++i) { var pa = Exp(len * (map[i][1] - map[i][0] + 1), mod - 2, mod); var ch = 0L; if (map[0][1] < map[i][1]) { ch += len * (map[i][1] - Math.Max(map[i][0] - 1, map[0][1])) % mod; } { var left = Math.Max(map[0][0], map[i][0]); var right = Math.Min(map[0][1], map[i][1]); if (left < right) ch += (right - left + 1L) * (right - left) / 2 % mod; } ans = (ans + pa * (ch % mod) % mod) % mod; } WriteLine(ans); } static long Exp(long n, long p, int mod) { long _n = n % mod; var _p = p; var result = 1L; if ((_p & 1) == 1) result *= _n; while (_p > 0) { _n = _n * _n % mod; _p >>= 1; if ((_p & 1) == 1) result = result * _n % mod; } return result; } }