import io,os,sys #https://recruit.gmo.jp/engineer/jisedai/blog/python_standard_io_with_bytesio/ buf = io.BytesIO() MOD = 998244353 max_K = 5*10**5 fact =[-1] * (max_K+1) #MOD下での階乗 inv =[-1] * (max_K+1) #MOD下での逆元 fact_inv=[-1] * (max_K+1) #MOD下での階乗の逆元 fact[0]=fact[1]=1 inv[1] = 1 fact_inv[0]=fact_inv[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 fact_inv[i] = (fact_inv[i-1]*inv[i])%MOD def c(n,r): if n < 0 or r < 0 or r > n: return 0 return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD input = sys.stdin.readline T = int(input()) block = 972 Qli = [[] for i in range(200001//block+1)] for i in range(T): l,r = map(int,input().split()) Qli[l//block].append(r*(200001)*(200001)+l*(200001)+i) l = 0 r = 0 ans = 0 answers = [0]*T f = 0 f2 = fact_inv[2] for li in Qli: if len(li)==0: continue for x in sorted(li,reverse = f): R = x//((200001)*(200001)) L = x//(200001)-R*(200001) i = x%(200001) while l > L: l -= 1 ans =(c(2*r, l+1) - 2*ans)%MOD while l < L: ans = ((c(2*r, l+1) - ans) * fact_inv[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 answers[i] = ans f^=1 print(*answers,sep="\n")