mod = 998244353 def solve(): n,m = map(int,input().split()) dp = [1,0,0] for i in range(m): ndp = [0]*3 for bi in range(3): rest = n-bi if rest < 0: continue ndp[0] += dp[bi] ndp[0] %= mod if rest == 0: continue ndp[1] += dp[bi] * rest ndp[1] %= mod if rest == 1 or n < 4: continue ndp[2] += (rest*(rest-1)//2 - (n-2*bi)) * dp[bi] ndp[2] %= mod dp = ndp return sum(dp)%mod t = int(input()) for _ in range(t): print(solve())