mod = 998244353 t = int(input()) for _ in range(t): n, m = [int(x) for x in input().split()] can_place_0 = 1 can_place_1 = n can_place_2 = max(n * (n - 1) // 2 - n, 0) can_place_2 %= mod for _ in range(m - 1): next_cp0 = can_place_0 + can_place_1 + can_place_2 next_cp1 = n * can_place_0 next_cp1 += (n - 1) * can_place_1 next_cp1 += (n - 2) * can_place_2 next_cp2 = max(n * (n - 1) // 2 - n, 0) * can_place_0 next_cp2 += ((n - 1) * (n - 2) // 2 - (n - 2)) * can_place_1 if n >= 4: next_cp2 += ((n - 2) * (n - 3) // 2 - (n - 4)) * can_place_2 can_place_0 = next_cp0 % mod can_place_1 = next_cp1 % mod can_place_2 = next_cp2 % mod print(can_place_0, can_place_1, can_place_2, (can_place_0 + can_place_1 + can_place_2) % mod)