#Lutece3221. 神秘的树

神秘的树

Migrated from Lutece 3221 神秘的树

All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.

Description

Tag: 另类拉格朗日反演,多项式高次幂远处系数求值

给定一个不包含 11 的正整数集 SS

定义一个树是神秘的当且仅当对于每个非叶节点,他的孩子数属于这个数集 SS

给定 S,M,TS,M,T

TT 组询问,询问有多少叶节点数为 nn 的神秘的树,对 MM 取模。

Input

第一行三个正整数 T,K,MT,K,M,表示询问的次数,SS 中数的范围,模数。

第二行一个长为 K1K-1 的 01 串,第 ii 位(从 1 开始)表示 i+1i+1 是否在 SS 中,1/0 表示 在/不在。

接下来 TT 行,每行一个正整数 nn,表示询问。

Output

输出 TT 行,每行一个正整数表示答案。

Samples

5 2 47
1
1
2
3
4
5
1
1
2
5
14
10 15 50
11101010101101
1
2
3
4
5
10
100
10000
998244353
1145141919810
1
1
3
11
44
27
31
30
10
26

Constraints

1T1001\le T \le 100

2K,M502\le K,M\le 50

1n10181\le n\le 10^{18}

Resources

2024 UESTC ICPC Training for Math