문제
Farmer John wrote down () digits on pieces of paper. For each , the th piece of paper contains digit ().
The cows have two favorite integers and (), and would like you to answer () queries. For the th query, the cows will move left to right across papers (), maintaining an initially empty pile of papers. For each paper, they will either add it to the top of the pile, to the bottom of the pile, or neither. In the end, they will read the papers in the pile from top to bottom, forming an integer. Over all ways for the cows to make choices during this process, count the number of ways that result in the cows reading an integer in inclusive, and output this number modulo .
입력
The first line contains three space-separated integers , , and .
The second line contains space-separated digits .
The third line contains an integer , the number of queries.
The next lines each contain two space-separated integers and .
출력
For each query, a single line containing the answer.
예제 입력 1
5 13 327
1 2 3 4 5
3
1 2
1 3
2 5
예제 출력 1
2
18
34
점수
Inputs 2-3: Inputs 4-5: Inputs 6-13: No additional constraints.
코드를 제출하려면 로그인이 필요합니다.
로그인