MOD = 998244353 def main(): import sys input = sys.stdin.read().split() ptr = 0 N, Q = int(input[ptr]), int(input[ptr + 1]) ptr += 2 A = list(map(int, input[ptr:ptr + N])) ptr += N B = list(map(int, input[ptr:ptr + Q])) dp = [0] * (N + 1) dp[0] = 1 current_max = 0 for a in A: tmp = [0] * (N + 1) for j in range(current_max + 1): # Case where we don't choose color 1 from this box tmp[j] = (tmp[j] + dp[j] * (a - 1)) % MOD # Case where we choose color 1 from this box if j + 1 <= N: tmp[j + 1] = (tmp[j + 1] + dp[j]) % MOD dp = tmp current_max += 1 for b in B: print(dp[b] % MOD) if __name__ == '__main__': main()