mod=998244353 T=int(input()) for tests in range(T): N,X=map(int,input().split()) if X%2==1: print(((N+1)//2)%mod) else: if N