This page is still under construction.

Parts of this page are still being built. What you see may change.

Test Passing Probability (Small)

Time limit5sMemory limit512 MB

Summary
With M submissions and Q questions of 4 choices each, find the maximum probability of answering every question correctly, learning only whether each submission passed.
Level

Medium7 of 10

Topics
Dynamic programming, Probability, Combinatorics
Solved
No attempts yet

Problem

Dave is taking a multiple choice test online. The test has QQ questions and each question offers 4 responses. Every submission must answer all of the questions, and Dave passes only if every answer is correct. The only thing he learns after a submission is whether he passed.

For each question Dave knows the probability that each of the 4 responses is the correct one, independently of the other questions. Given the number of submissions MM he is allowed, Dave picks his answers so that the probability of passing is as large as possible.

Compute 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 MM and QQ. MM is the number of submissions Dave may make and QQ is the number of questions on the test. The next QQ lines each contain the 4 probabilities of correctness for one question, in the order of the responses. Each probability has at most 6 digits after the decimal point, every probability is non-negative, and the four values on a line sum to 1.

  • 1≤C≤1001 \le C \le 100
  • 1≤Q≤61 \le Q \le 6
  • 1≤M≤10001 \le M \le 1000

Output

For each test case, print one line of the form Case #X: Y, where XX is the test case number starting from 1 and YY is the probability of passing.

Print YY rounded at the seventh digit after the decimal point, with all 6 decimal digits present. A probability of exactly 11 prints as 1.000000. In the data for this problem the true answer is at least 10−910^{-9} away from a rounding boundary.

Examples3

  1. Example 1

    Input
    3
    10 2
    0.25 0.25 0.25 0.25
    0.25 0.25 0.25 0.25
    64 3
    0.3 0.4 0.0 0.3
    1.0 0.0 0.0 0.0
    0.2 0.2 0.2 0.4
    3 2
    0.5 0.17 0.17 0.16
    0.5 0.25 0.25 0.0
    
    Expected output
    Case #1: 0.625000
    Case #2: 1.000000
    Case #3: 0.500000
    
  2. Example 2

    Input
    1
    1 1
    0.25 0.25 0.25 0.25
    
    Expected output
    Case #1: 0.250000
    
  3. Example 3

    Input
    1
    5 3
    0.250000 0.250000 0.250000 0.250000
    0.250000 0.250000 0.250000 0.250000
    0.250000 0.250000 0.250000 0.250000
    
    Expected output
    Case #1: 0.078125