Shut the Box I

No attempts yetTime limit1sMemory limit128 MB

Problem

The Avengers' pursuit of the Collector has taken them on a long voyage through the galaxies, and they look for ways to pass the time on their ship. They discover an old game called Shut the Box, once popular with sailors.

Each player starts with 9 cards numbered $1$ through $9$, laid face-up on the table, and keeps playing until no move is possible.

The game uses a pair of dice, with one twist: only a single die is used when the total of the open (face-up) cards is $\le 6$. Initially every card is face-up. The player rolls the dice; let the total be $m$. The player then chooses any set of open cards whose face values sum to exactly $m$ and shuts (turns face-down) that set.

For example, if the player rolls a $6$ and a $2$ (total $8$) on the first turn, they may shut the card $8$, or the cards $1$ and $7$, or the cards $2$ and $6$, or the three cards $1, 2, 5$, and so on. As another example, if the open cards are $1, 2, 6$ and the player rolls a $4$, then no set of cards sums to $4$, so no move is possible and the turn is over.

The final score is the sum of the cards still face-up; the aim is to make the score as low as possible (ideally to "shut the box", leaving no card face-up). In the case above that ends with $1, 2, 6$ still open, the final score is $1 + 2 + 6 = 9$.

Illustration of the Shut the Box game

Figure 1: Illustration of the Shut the Box game in two cases (in the right example, only the last few moves are shown). Note that only one die is used when the total of the open cards is $\le 6$ (the right example).

Dr. Banner (the Hulk) follows this strategy. Consider every valid set of cards that can be shut for the current roll:

  • If there is only one, take it.
  • If there are several, take the one that maximizes the smallest face value. For example, given the options ${1, 7}$ and ${2, 6}$, take ${2, 6}$.
  • If several still tie on the smallest face value, take the one that maximizes the second-smallest face value. For example, given ${2, 4, 6}$ and ${2, 3, 7}$, take ${2, 4, 6}$.

In general, among the valid options, select the one whose face values, listed in ascending order, form the lexicographically largest sequence.

Write a program that makes this choice for Dr. Banner (you know what happens when the Hulk is angered).

Input

The first line contains the number of test cases $T$ (with $T < 100$).

Each of the next $T$ lines describes one test case. The line begins with the rolled total (the target), followed by the number of open cards $n$, followed by the $n$ open card values in ascending order.

Output

For each test case, output one line.

If at least one valid move exists, print the best move (per the strategy above) in this exact form:

The best move is: c1 c2 ... ck

where $c_1, c_2, \dots, c_k$ are the chosen card values in ascending order, separated by single spaces.

If no set of open cards sums to the target, print exactly:

No move found.