Test Passing Probability (Large Input)

With M submissions allowed and independent per-question probabilities, choose answers to maximize the chance that one submission is fully correct.

Hard8ProbabilityDynamic programmingGreedyNo attempts yetTime limit5sMemory limit512 MB

Problem

Dave is taking a multiple choice test online. He may submit his answers several times, but he passes only if one of his submissions has every question right. Every submission must carry an answer to every question, and the only thing he learns after a submission is whether he passed.

For each question Dave has estimated the probability that each of the four responses is the correct one. Those probabilities are independent of what he writes on the other questions. Given how many submissions he is allowed, Dave picks his answers so that the probability of passing is as large as possible.

Find the probability that Dave passes when he picks his answers optimally.

Input

The first line contains the number of test cases CC. CC test cases follow.

The first line of each test case contains the number of submissions MM that Dave may make and the number of questions QQ on the test. QQ lines follow, and each of them gives, in order, the four probabilities of correctness for one question. Every probability is at least 0 and has at most six digits after the decimal point, and the four probabilities on one line sum to 1.

Constraints

  • 1C1001 \le C \le 100
  • 1Q301 \le Q \le 30
  • 1M100001 \le M \le 10000

Output

For each test case, print one line holding Case #X: Y. XX is the number of the test case, starting from 1. YY is the largest passing probability, rounded to six digits after the decimal point and always printed with all six digits. A probability of exactly 0.50.5 is printed as 0.500000.