T = int(input()) MOD = 998244353 for _ in range(T): W, H = map(int, input().split()) dp = [[0]*3 for _ in range(H)] dp[0][0] = 1 dp[0][1] = W dp[0][2] = W*(W-3)//2 for i in range(H-1): dp[i+1][0] = sum(dp[i])%MOD dp[i+1][1] += dp[i][0]*W%MOD dp[i+1][1] %= MOD dp[i+1][1] += dp[i][1]*(W-1)%MOD dp[i+1][1] %= MOD dp[i+1][1] += dp[i][2]*(W-2)%MOD dp[i+1][1] %= MOD if 4 <= W: dp[i+1][2] += dp[i][0]*dp[0][2]%MOD dp[i+1][2] %= MOD if 4 < W: dp[i+1][2] += dp[i][1]*(dp[0][2]-(W-3))%MOD dp[i+1][2] %= MOD dp[i+1][2] += dp[i][2]*(dp[0][2]-((W-3)*2-1))%MOD dp[i+1][2] %= MOD else: dp[i+1][2] += dp[i][1]+dp[i][2] dp[i+1][2] %= MOD print(sum(dp[-1])%MOD)