Mousetrap (Small)

For each query index, report which card occupies that position in the unique deck that removes cards in order 1..K.

Medium4QueueSimulationMathNo attempts yetTime limit30sMemory limit512 MB

Problem

Mousetrap is a simple card game for one player. You start with KK cards numbered 1 through KK, shuffled and stacked face down in a single deck.

One move works like this. Set the count to 1 and reveal the top card of the deck. If its number equals the current count, remove that card from the deck and reset the count to 1. Otherwise move that card to the bottom of the deck and increase the count by 1. If the count ever reaches K+1K+1, you lose. If you remove every card, you win.

Consider a deck of 5 cards holding 2, 5, 3, 1, 4 from the top. You reveal the 2 on count 1, the 5 on count 2, and the 3 on count 3. The number equals the count, so you remove the 3 and reset the count to 1. The four remaining cards read 1, 4, 2, 5 from the top. You reveal the 1 on count 1 and remove it right away, and in the same way you go on to remove the 2, the 4 and the 5 for a win.

Now work in the other direction and lay out the deck yourself. Call a deck perfect if it wins the game and the cards leave in numerical order, that is 1, then 2, then 3, on up to KK. With 4 cards, the arrangement 1, 4, 2, 3 from the top wins and removes the cards in the order 1, 2, 3, 4.

Once KK is fixed, the perfect deck is determined. Index 1 of the deck is the top card and index KK is the bottom card. Report which card sits at a given index of the perfect deck.

Input

The first line contains the number of test cases TT.

Each test case takes two lines. The first line contains KK, the number of cards in the deck. The second line contains the number of queries nn, followed by the deck indices d1,d2,,dnd_1, d_2, \dots, d_n separated by spaces.

Limits

  • 1T1001 \le T \le 100
  • 1K50001 \le K \le 5000
  • 1n1001 \le n \le 100
  • 1diK1 \le d_i \le K

Output

For each test case, print one line starting with Case #x: and then the nn integers k1,k2,,knk_1, k_2, \dots, k_n. Here xx is the test case number counted from 1, and kik_i is the number of the card at index did_i of the perfect deck of size KK.

Put exactly one space after the colon and separate the printed integers with one space each.