N,Q = map(int, input().split()) A = [int(a) for a in input().split()] B = [int(b) for b in input().split()] mod = 998244353 L = [[0]*(N+1) for _ in range(N+1)] L[0][0] = 1 for i in range(N): for j in range(i+2): L[i+1][j] += L[i][j]*(A[i]-1) if j > 0: L[i+1][j] += L[i][j-1] L[i+1][j] %= mod for b in B: print(L[N][b])