Landlords

์•„์ง ์ œ์ถœ์ด ์—†์Šต๋‹ˆ๋‹ค์‹œ๊ฐ„ ์ œํ•œ1์ดˆ๋ฉ”๋ชจ๋ฆฌ ์ œํ•œ512 MB

๋ฌธ์ œ

Kevin is playing cards and now he needs to shuffle cardsย ๐‘šmย times. Now let's describe the rule of the ithย shuffle.

For the ithย shuffle:

  1. Kevin will take out Aiย cards from the top and make it a new pile. Now there are two piles of cards. One is the original topย Aiย cards and the other is the rest n โˆ’ Aiย cards. The relative order in these two piles remains unchanged. Note that whenย Aiย is nย or 0, there is one pile which has no card at all.
  2. Now let's merge those two piles of cards into a new pile. Suppose the first pile has Xย cards and the second piles has Yย cards. With probabilityย X/(X + Y), we select the bottom card of the first pile and put the selected card to the top of the new pile. Then, with probability Y/(X + Y), we select the bottom card of the second pile and then put the selected card to the top of the new pile.
  3. Repeat 2 until both piles are empty.

Now we have Qย questions for you. You have to tell us after mย times of shuffles, what's the expected score of some specific positions' card. Note that for card i, let's denote its score as f(i). In this problem, f(i)ย equals to either iย or i2.

์ž…๋ ฅ

The first line contains three integers n, m, type. When type = 1, f(i) = i. When type = 2, f(i) = i2.

The following line contains mย integers A1 โ€ฆ Am.

The following line contains an integerย Q.

In the following Qย lines, each line contains an integerย ci (1 โ‰ค ci โ‰ค n), indicating that Kevin wants to know the expected score of the ciย position from top.

์ถœ๋ ฅ

For each query, output a single integer on a single line as the answer. If the answer is A/B, please print C (0 โ‰ค C < 998244353)ย where A โ‰ก C ร— B (mod 998244353).

์ œํ•œ

For all test cases, 3 โ‰ค n โ‰ค 107, 1 โ‰ค m, Q โ‰ค 5 ร— 105, 0 โ‰ค Ai โ‰ค n, typeย โˆˆ [1,2].