import sys input=lambda: sys.stdin.readline().rstrip() n,q=map(int,input().split()) A=[int(i) for i in input().split()] B=[int(i) for i in input().split()] mod=998244353 DP=[[0]*(n+1) for i in range(n+1)] for i in range(n+1): DP[i][0]=1 for i,a in enumerate(A): for j in range(i+1): DP[i+1][j+1]=((a-1)*DP[i][j]+DP[i][j+1])%mod for b in B: print(DP[n][n-b])