import sys input = sys.stdin.readline mod = 998244353 n = 2*10**5+5 fact = [1] * (n + 1) invfact = [1] * (n + 1) for i in range(1, n): fact[i + 1] = ((i+1) * fact[i]) % mod invfact[n] = pow(fact[n], mod - 2, mod) for i in range(n - 1, -1, -1): invfact[i] = invfact[i + 1] * (i + 1) % mod def comb(n, r): if n < 0 or r < 0 or n - r < 0: return 0 return fact[n] * invfact[r] * invfact[n - r] % mod def f(N, k): ma = (N + 1)//2 if k > (N + 1 - ma) * ma: return -1 if k == (N + 1 - ma) * ma: return ma if k == 0: return 0 yes = ma no = 0 while yes - no != 1: mid = (yes + no)//2 if k <= mid * (N + 1 - mid): yes = mid else: no = mid if k == yes * (N + 1 - yes): return yes else: return -1 T = int(input()) for _ in range(T): N, K = map(int, input().split()) if N % 2 and K == ((N + 1)//2) ** 2: print(comb(N + 1, (N + 1)//2) * pow(2, mod - 2, mod) % mod) else: print(comb(N + 1, f(N, K)))