mod = 998244353 n, q = gets.to_s.split.map{|t| t.to_i } a = gets.to_s.split.map{|t| t.to_i } b = gets.to_s.split.map{|t| t.to_i } dp = Array.new(n+1){ [0] * (n+2) } dp[0][0] = 1 a.each_with_index do |t, i| i.downto(0) do |j| dp_cur = dp[i][j] dp[i+1][j] = ( dp[i+1][j] + dp_cur * (t - 1) ) % mod dp[i+1][j+1] = ( dp[i+1][j+1] + dp_cur ) % mod end end b.map!{|t| dp[n][t] % mod } puts b.join("\n")