MOD = 998244353i64 def inv(v : Int64) pow(v, MOD - 2) end def pow(v : Int64, p) ret = 1i64 while p > 0 if (p & 1i64) != 0 ret *= v ret %= MOD end v *= v v %= MOD p >>= 1 end ret end n = read_line.to_i l0, r0 = read_line.split.map(&.to_i64) ans = 1i64 (n - 1).times do l1, r1 = read_line.split.map(&.to_i64) next if r1 <= l0 if r0 < l1 ans += 1 next end add = 0i64 if l0 < l1 add += (l1 - l0) * (r1 - l1 + 1) end lo = {l0, l1}.max hi = {r0, r1}.min add += ((r1 - lo) + (r1 - hi)) * (hi - lo + 1) // 2 add *= inv(r0 - l0 + 1) add %= MOD add *= inv(r1 - l1 + 1) add %= MOD ans += add end puts ans % MOD