T=int(input()) mod=998244353 for t in range(T): N,K=map(int,input().split()) ans=0 for k in range(2,2+K): ans+=pow(k,N,mod) ans%=mod print(ans)