×

- 32.85%
- 524288K

John is not only a magic master but also a shuffling master.

Famous though he is, he likes interacting with his fans by playing a game with his fantastic shuffling skills.

The game shows as follows:

He first shows a deck of pokers contains $N$ cards indexed $1,2,\dots ,N$ and all the cards are the same. He notes that the side contains numbers as the front side and the other side as the back. Later he selects one of his fans to choose a positive integer $M$ that is not greater than $10$. After that, he will shuffle the cards purposefully and put it on the desktop. Note that at this moment the front sides of the cards are facing to the desk.

Then, the selected fans should perform the following steps until there is no card on the desk.

- Place the card on the top of the piles to John's hand. If there are already some cards in his hand, put it on the top of them.
- If there remain cards on the desk:

(a) Put a card from the top of the piles to the bottom of it.

(b) Execute the step ($a$) of $M$ times.

(c) Go to step $1$.

Next, it is time to witness the miracle.

John will continually overturn the cards on his hand top to bottom, and we will find that the cards are always in decreasing order.

One day, one of John's fans, Tom, a smart JBer, understands the key to this magic. He turns to you and comments that the key to that magic is the shuffling John did previously. For any number $M$, he will turn the cards in a specific order after the shuffling. As you are not as smart as Tom, you should find the index of the $K$th cards from the top of the piles after the shuffling.

The first line contain a positive integer $T (1\le T \le10)$ – the number of test cases.

For each test cases, the first line contain a positive integer $N (1 \le N \le 40000000)$ , indicating the numberof cards.

The second line contain a positive integer $M (1\le M \le 10)$ – the number the fans select.

The third line contain an integer $Q (1 \le Q \le 100)$ – indicating that there are $Q$ questions.

Next, there are $Q$ lines, each with an integer $K (1 \le K \le N)$ – representing a query.

For each query, you should output the index of the $K$th cards from the top of the piles after the shuffling.

1 5 1 2 2 3

5 2

Sample description - The indexs of the cards after the shuffling are: $1~5~2~4~3$ (Left is top)