import sys input = sys.stdin.readline 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) ans %= mod print(ans)