mod = 998244353

n, q = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

dp = [0] * (n + 1)
dp[0] = 1
current_max_j = 0  # Tracks the maximum j with non-zero value

for a in A:
    new_dp = [0] * (n + 1)
    ai_minus_1 = (a - 1) % mod
    for j in range(current_max_j + 1):
        val = dp[j]
        if val == 0:
            continue
        # Not choosing color 1 from this box
        new_dp[j] = (new_dp[j] + val * ai_minus_1) % mod
        # Choosing color 1 from this box
        if j + 1 <= n:
            new_dp[j + 1] = (new_dp[j + 1] + val) % mod
    dp = new_dp
    current_max_j = min(current_max_j + 1, n)

# Prepare the results for each query
results = [dp[b] % mod for b in B]
print(' '.join(map(str, results)))