#region Header #!/usr/bin/env python3 # from typing import * import sys import io import math import collections import decimal import itertools from queue import PriorityQueue import bisect import heapq def input(): return sys.stdin.readline()[:-1] sys.setrecursionlimit(1000000) #endregion # _INPUT = """4 3 # 1 3 3 3 # 3 1 4 # """ # sys.stdin = io.StringIO(_INPUT) MOD = 998244353 def main(): N, Q = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) dp = [0 for _ in range(N+1)] dp[0] = 1 for i in range(N): dp1 = [0 for _ in range(N+1)] for k in range(N+1): if dp[k] > 0: dp1[k] = (dp1[k] + dp[k] * (A[i] - 1)) % MOD dp1[k+1] = (dp1[k+1] + dp[k]) % MOD dp = dp1 for b in B: print(dp[b]) if __name__ == '__main__': main()