from functools import cmp_to_key from sys import stdin input = stdin.readline mod = 998244353 fact = [1] mx = 5 * 10 ** 5 + 1 for i in range(1, mx): fact.append(fact[-1] * i % mod) facti = [] for f in fact: facti.append(pow(f, mod-2, mod)) block = 450 t = int(input()) query = [[] for _ in range(2 * 10 ** 5 // block + 1)] for i in range(t): n,m = map(int,input().split()) query[n // block].append([m,n,i]) def c(n, r): if n < 0 or r < 0 or r > n: return 0 return (fact[n] * facti[r] % mod) * facti[n-r] % mod # query.sort(key=cmp_to_key(cmp)) answer = [0] * t ans = 1 l = 1 r = 1 for i in range(len(query)): if not query[i]: continue query[i].sort(reverse=(i%2 == 1)) for qi in query[i]: R, L, id = qi while l > L: l -= 1 ans = c(2*r, l+1) - 2*ans ans %= mod while l < L: ans = (c(2*r, l+1) - ans) * facti[2] l += 1 ans %= mod while r > R: ans = ans - c(2*r-2, l-1) r -= 1 ans %= mod while r < R: r += 1 ans = ans + c(2*r-2, l-1) ans %= mod answer[id] = str(ans) print("\n".join(answer))