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