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