from functools import cmp_to_key from sys import stdin input = stdin.readline fact = [1] mx = 5 * 10 ** 5 + 1 for i in range(1, mx): fact.append(fact[-1] * i % 998244353) facti = [] for f in fact: facti.append(pow(f, 998244351, 998244353)) block = 500 t = int(input()) query = [] for i in range(t): n,m = map(int,input().split()) query.append([n,m,i]) def cmp(x, y): xb = x[0] // block yb = y[0] // block if xb > yb: return 1 elif xb < yb: return -1 sign = xb % 2 == 0 if sign ^ (x[1] > y[1]): return -1 else: return 1 def c(n, r): if n < 0 or r < 0 or r > n: return 0 return fact[n] * facti[r] * facti[n-r] % 998244353 query.sort(key=cmp_to_key(cmp)) answer = [0] * t ans = 1 l = 1 r = 1 modlim = 10 ** 15 for qi in query: L, R, id = qi while l > L: l -= 1 ans = c(2*r, l+1) - 2*ans # if ans > modlim: # ans %= 998244353 while l < L: ans = (c(2*r, l+1) - ans) * facti[2] l += 1 # if ans > modlim: # ans %= 998244353 while r > R: ans = ans - c(2*r-2, l-1) r -= 1 # if ans > modlim: # ans %= 998244353 while r < R: r += 1 ans = ans + c(2*r-2, l-1) # if ans > modlim: # ans %= 998244353 ans %= 998244353 answer[id] = str(ans) print("\n".join(answer))