import sys input = lambda :sys.stdin.readline()[:-1] ni = lambda :int(input()) na = lambda :list(map(int,input().split())) yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES") no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO") ####################################################################### mod = 998244353 nn = 10**6 fact = [1] * nn for i in range(nn - 1): fact[i + 1] = fact[i] * (i + 1) % mod invfact = [1] * nn invfact[nn - 1] = pow(fact[nn - 1], mod - 2, mod) for i in range(nn - 1)[::-1]: invfact[i] = invfact[i + 1] * (i + 1) % mod def binom(x, y): if x < 0 or y < 0 or x - y < 0: return 0 return fact[x] * invfact[y] % mod * invfact[x - y] % mod que = [] t = ni() B = 500 ans = [None] * t for _ in range(t): n,m = na() que.append((n//B, m, n, _)) que = sorted(que) sm, sn = 1, 1 sum = 1 z = pow(2, mod-2, mod) for q in que: _, m, n, i = q #print(sum) if sm < m: for x in range(sm, m): sum += binom(sn-1, x) sum %= mod else: for x in range(sm, m, -1): sum -= binom(sn-1, x-1) sum %= mod if sn < n: for x in range(sn, n): sum = (sum * 2 - binom(x-1, m-1))%mod else: for x in range(sn, n, -1): sum = (sum + binom(x-2, m-1))*z %mod sum %= mod ans[i] = sum * (pow(2, n, mod)-1)%mod sn, sm = n, m print(*ans, sep = "\n")