#P7812. Expression

Expression

Expression

Problem Description

You are given an expression string of length LL consisting of variables and +, , , ()+,\space -,\space *,\space (). The symbol [k][k] is used to denote the variable xkx_k (k[1,n])(k \in [1,n]) . It is assumed that there are nn different variables in total. It guarantees that each variable appears only once. So the expression string can be regarded as a multivariate function f(x1,x2,,xn)f(x_1,x_2,\cdots,x_n). We denote:

$$g(t)=\sum_{1 \le i_1,i_2,\cdots, i_t \le n} h(i_1,i_2,\cdots,i_t; t) $$$$h(i_1,i_2,\cdots,i_t; t)= \frac{\partial^{t} }{\partial x_{i_1} \partial x_{i_2} \cdots \partial x_{i_t}} f $$

For the given value of xi,i[1,n]x_i,i \in [1,n]. You have the following two tasks. 1.Calculate g(0),g(1),,g(5).g(0),g(1),\cdots,g(5). 2.For the following m queries, you are given t[1,30], i1,i2,,it[1,n]t \in [1,30],\ i_1,i_2,\cdots,i_t\in [1,n], print the answer h(i1,i2,,it;t).h(i_1,i_2,\cdots,i_t; t). Since they may be too large, print all of them mod 998244353mod \ 998244353. If you knew little about higher-order partial and mixed derivatives, you can refer to https://en.wikipedia.org/wiki/Partial_derivative#Notation.

Input

The first line contains an integer TT denoting the number of test cases. For each test case: The first line contains two integers LL and nn --- LL represents the length of expression string and nn represents the number of variables. The second line contains one string consisting of variables and +, , , ()+,\ -,\ *,\ (). The third line contains nn integers, which are the values of xix_i. The fourth line contains a integer mm denoting the number of query. The ii-th of the following mm lines denotes the ii-th query, \space which contains integers t,i1,i2,,itt,i_1,i_2, \cdots, i_t. It guarantees that: $T \in [1,20],\space x_i \in [-10^8,10^8],\space L \in [1,10^5],\space\sum L \in [1,3 \times 10^5].$ $n \in [1,10^4],\space\sum n \in [1,3 \times 10^4],\space\sum t \in [1,10^7],\space\sum m \in [0,8 \times 10^5].$

Output

For each test, print m+1m + 1 lines. The first line outputs 66 integers: the ii-th integer means g(i1) mod 998244353, i[1,6]g(i-1) \ mod \ 998244353 ,\ i \in [1,6]. For the ii-th of the following mm lines, print the answer of ii-th query mod 998244353.mod \ 998244353.

Sample Input

1
11 3
[1]*[2]*[3]
1 2 3
3
1 1
2 1 2
3 1 2 3

Sample Output

6 11 12 6 0 0
6
3
1

Source

2020 Multi-University Training Contest 5