Easy Counting Problem
题号:NC239613
时间限制:C/C++/Rust/Pascal 8秒,其他语言16秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
Special Judge, 64bit IO Format: %lld

题目描述

See Problem N for PDF statements.
Yukikaze is learning stringology. She found a series of interesting problems at the end of her textbook as follows.

We consider a string to be good if it satisfies the following conditions:
  •  It consists of decimal digits less than w.
  •  Digit i appears at least c_i times.
We consider two strings to be different if they are different in length or there exists an integer i such that the letters in their i-th position are different.
The problem in the textbook asks for the number of different good strings of length n.

输入描述:

The first line contains a single integer w (), indicating that a good string consists of decimal digits less than w.

The second line contains w integers (, ), indicating that the decimal digit i appears at least c_i times in a good string.

The third line contains a single integer q (), indicating the number of queries.

Each of the next q lines contains a single integer n (), indicating the length of the string.

输出描述:

For each query, output an integer in a single line indicating the number of different good strings of length n. As the answer may be large, please output the answer modulo 998244353.
示例1

输入

复制
2
1 1
3
3
5
7

输出

复制
6
30
126

说明

If we set n=3, w=2, c_0=c_1=1, then the answer is 6, including \texttt{001}, \texttt{010}, \texttt{011}, \texttt{100}, \texttt{101}, \texttt{110}.
示例2

输入

复制
6
11 45 14 11 45 14
3
114514
1919
810

输出

复制
519265932
6372511
784491879