MOD = 998244353 K, M, W = 119, 23, 31 # https://qiita.com/izu_nori/items/1c5cdef0500ffa0276f5 class NTT: def __init__(self): self.ws = [pow(W, 2**i, MOD) for i in range(M, -1, -1)] self.iws = [pow(w, MOD - 2, MOD) for w in self.ws] def convolution(self, f, g): nf = len(f) ng = len(g) m = nf + ng - 1 n = 2 ** (m - 1).bit_length() f = [x % MOD for x in f] + [0] * (n - nf) g = [x % MOD for x in g] + [0] * (n - ng) self.ntt(f) self.ntt(g) for i in range(n): f[i] = f[i] * g[i] % MOD self.intt(f) return f[:m] def ntt(self, A): if len(A) == 1: return n = len(A) k = n.bit_length() - 1 r = 1 << (k - 1) for w in self.ws[k:0:-1]: for l in range(0, n, 2 * r): wi = 1 for i in range(r): A[l + i], A[l + i + r] = (A[l + i] + A[l + i + r]) % MOD, (A[l + i] - A[l + i + r]) * wi % MOD wi = wi * w % MOD r = r // 2 def intt(self, A): if len(A) == 1: return n = len(A) k = (n - 1).bit_length() r = 1 for w in self.iws[1 : k + 1]: for l in range(0, n, 2 * r): wi = 1 for i in range(r): A[l + i], A[l + i + r] = (A[l + i] + A[l + i + r] * wi) % MOD, (A[l + i] - A[l + i + r] * wi) % MOD wi = wi * w % MOD r = r * 2 ni = pow(n, MOD - 2, MOD) for i in range(n): A[i] = A[i] * ni % MOD FACT_SIZE = 3000 fact = [1] * FACT_SIZE for i in range(1, FACT_SIZE): fact[i] = fact[i - 1] * i % MOD ifact = [1] * FACT_SIZE ifact[FACT_SIZE - 1] = pow(fact[FACT_SIZE - 1], MOD - 2, MOD) for i in range(FACT_SIZE - 1, 0, -1): ifact[i - 1] = ifact[i] * i % MOD h, w = map(int, input().split(" ")) f = [fact[w]] ntt = NTT() for _ in range(h): a, b = map(int, input().split(" ")) a -= 1 g = [0] * (w + 1) ff_a, ff_b = 1, 1 for n in range(w): ff_a = ff_a * (w + a - n) % MOD ff_b = ff_b * (w + b - n) % MOD for n in range(w + 1): g[n] = ifact[n] * ifact[w + n] % MOD * (ff_b - ff_a) % MOD ff_a = ff_a * (a - n) % MOD ff_b = ff_b * (b - n) % MOD f = ntt.convolution(f, g)[: w + 1] print(f[w])