from functools import cmp_to_key from sys import stdin input = stdin.readline MOD = 998244353 max_K = 10**6 fact =[-1] * (max_K+1) #MOD下での階乗 inv =[-1] * (max_K+1) #MOD下での逆元 facti=[-1] * (max_K+1) #MOD下での階乗の逆元 fact[0]=fact[1]=1 inv[1] = 1 facti[0]=facti[1] = 1 for i in range(2,max_K+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 = 800 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 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))# ans %= MOD answer[id] = str(ans) print("\n".join(answer))