from functools import cmp_to_key from sys import stdin input = stdin.readline mod = 998244353 fact = [1] mx = 4 *10** 5 + 1 fact =[-1] * (mx+1) #MOD下での階乗 inv =[-1] * (mx+1) #MOD下での逆元 facti=[-1] * (mx+1) #MOD下での階乗の逆元 fact[0]=fact[1]=1 inv[1] = 1 facti[0]=facti[1] = 1 for i in range(2,mx+1): fact[i] = (fact[i-1]*i)%mod inv[i] = (-inv[mod%i]*(mod//i))%mod facti[i] = (facti[i-1]*inv[i])%mod block = 900 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) % mod while l < L: ans = ((c(2*r, l+1) - ans) * facti[2]) % mod l += 1 while r > R: ans = (ans - c(2*r-2, l-1)) % mod r -= 1 while r < R: r += 1 ans = (ans + c(2*r-2, l-1)) % mod answer[id] = str(ans) print("\n".join(answer))