Shut the Box II

No attempts yetTime limit1sMemory limit128 MB

Problem

Shut the Box is a dice game played with a row of cards, each labelled with a distinct positive integer. Every card is either open (face up) or shut (face down). On each turn you roll dice and read their total; you must then shut some set of currently open cards whose values add up to exactly that total. If no such set exists, your turn ends and the box is not shut. You win when every card has been shut ("the box is shut").

There is a twist in the dice rule. Normally two fair dice are rolled, so all 36 ordered outcomes are equally likely and the total runs from 2 to 12. But whenever the total value of the still-open cards is 6 or less, a single fair die is rolled instead (total 1 to 6, each with probability $1/6$).

Dr. Banner keeps losing at Shut the Box and is about to lose his temper. To calm him, you must give him the best move: given the open cards and the total he has just rolled, choose the set of open cards to shut that maximizes the probability of eventually shutting the box under optimal future play. You must also report that probability.

For example, suppose the open cards are 1, 2, and 3 and the rolled total is 3. Two moves are possible:

  • Shut 1 and 2. Card 3 remains, so the box is shut only if the next roll (one die, since the open total is 3) is a 3: probability $1/6 \approx 0.1667$.
  • Shut 3. Cards 1 and 2 remain, and the probability of eventually shutting them is $\frac{1}{6} + \frac{2}{6}\cdot\frac{1}{6} = \frac{8}{36} \approx 0.2222$.

The second move is better, so it is the answer.

Input

The first line contains the number of test cases $T$ ($T < 100$). Each of the next $T$ lines describes one test case: the rolled total (the target), then the number of open cards $n$, then the $n$ open card values in ascending order, all separated by spaces.

Output

For each test case, print one line.

  • If at least one set of open cards sums to the target, output the best such move as The best move is: <cards>, and probability of shutting = <p> where <cards> are the shut card values in ascending order separated by single spaces, and <p> is the probability of eventually shutting the box after that move. Print the probability rounded to four decimal places, except print exactly 1 when the move shuts every remaining card (probability 1).
  • If no set of open cards sums to the target, output No move found.

When several moves reach the same maximum probability, choose the one whose ascending list of shut cards is lexicographically smallest.

Constraints

  • $1 \le T < 100$.
  • The open cards on each line are distinct positive integers given in ascending order.
  • Two fair dice are used, except when the total of the open cards is at most 6, in which case a single fair die is used.