Mousetrap (Large Input)

In the perfect Mousetrap deck of K cards, report the card value at each queried position.

Medium7SimulationImplementationMathNo attempts yetTime limit5sMemory limit512 MB

Problem

Mousetrap is a card game for one player. The deck holds KK cards numbered 1 through KK, stacked face down. You reveal the top card of the deck, put that card on the bottom, and keep count of how many cards you have revealed. The first card you reveal is counted as 1. If the number on the revealed card equals the current count, you remove that card from the deck and reset the count, so the next card you reveal is counted as 1 again. If the count reaches K+1K+1, you lose. If the deck runs out of cards, you win.

Play a deck of 5 cards that reads 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 matches the count, so you remove the 3 and reset the count. The four remaining cards read 1, 4, 2, 5 from the top. You reveal the 1 on count 1 and remove it as well. Going on the same way you remove the 2, then the 4, then the 5, and you win.

A deck is perfect if playing the game with it wins and the removed cards come out in increasing order 1, 2, \dots, KK. With 4 cards the deck 1, 4, 2, 3 is perfect, because the cards come out in the order 1, 2, 3, 4. For every KK there is exactly one perfect deck of size KK, so the card at each position is determined.

Report which card sits at each of several positions of the perfect deck of size KK.

Input

The first line contains the number of test cases TT. Each test case is two lines. The first line contains KK, the number of cards in the deck. The second line contains an integer nn, followed by nn integers d1,d2,,dnd_1, d_2, \dots, d_n, the positions you are asked about. Position 1 is the top card of the deck and position KK is the bottom card.

  • 1T101 \le T \le 10
  • 1K1061 \le K \le 10^6
  • 1n1001 \le n \le 100
  • 1diK1 \le d_i \le K

The positions inside one test case need not be distinct and need not be sorted.

Output

Print one line for each test case. Print Case #x: first, then nn integers k1,k2,,knk_1, k_2, \dots, k_n separated by single spaces. Here xx is the test case number starting from 1, and kik_i is the number of the card at position did_i of the perfect deck of size KK. Put exactly one space after the colon as well.