Upstairs and Downstairs

Konstantin chooses and orders at least K activities from limited copies to minimize the chance Ilia wakes after falling asleep.

Hard8ProbabilityDynamic programmingGreedySortingNo attempts yetTime limit5sMemory limit512 MB

Problem

Konstantin and Ilia live in the same house. Konstantin lives upstairs and likes activities that involve jumping, moving furniture around and making noise. Ilia lives downstairs and likes to sleep.

To have a good evening, Konstantin wants to perform at least KK activities. Last night Ilia asked him not to wake him up, and Konstantin agreed. He took the request literally, so he picks his activities so that the probability of waking Ilia after Ilia has fallen asleep is as small as possible.

Activity ii has a probability ai/bia_i / b_i attached to it. When Konstantin performs that activity, Ilia is awake at the moment it ends with probability ai/bia_i / b_i and asleep otherwise. Ilia's state before the activity does not change this probability. Konstantin can perform activity ii at most cic_i times. Doing it more often bores him, and a bored Konstantin does not have a good evening.

Konstantin fixes the whole sequence of activities in advance, so that:

  • the sequence holds at least KK activities;
  • activity ii appears at most cic_i times;
  • the probability QQ that Ilia is woken up at least once is as small as possible.

Ilia starts the evening awake. He is woken up when he is asleep at the moment one activity ends and awake at the moment the next activity ends. Konstantin cannot see whether Ilia is awake or asleep, so he cannot change the plan while the evening goes on.

Find the smallest QQ Konstantin can reach.

Input

The first line holds the number of test cases TT. Each test case starts with a line holding two integers NN and KK. The next NN lines describe one activity each in the format a/b c: the activity leaves Ilia awake with probability a/ba/b at the moment it ends, and Konstantin can perform it at most cc times.

Limits

  • 1T1001 \le T \le 100
  • 1N1001 \le N \le 100
  • 0aibi10000000 \le a_i \le b_i \le 1000000
  • 1bi1 \le b_i and 1ci1 \le c_i for every ii
  • The sum of all cic_i in one test case is at most 100100.
  • 1K1 \le K \le the sum of all cic_i in that test case.

Output

For each test case print one line in the format Case #x: Q, where xx is the test case number starting from 1 and QQ is the smallest probability that Ilia is woken up. Print QQ with exactly nine digits after the decimal point.

Every answer is a rational number, and no answer lies within 101210^{-12} of a value halfway between two nine digit decimals, so rounding a double precision result gives the required digits.