Runaway Quail

Catch quails that flee in both directions on a line at given speeds by choosing the left-right chase order with the smallest total time.

Medium7Dynamic programmingMathNo attempts yetTime limit5sMemory limit512 MB

Problem

All NN of your pet quail have gotten loose. You stand at coordinate 00 on a line. Quail ii starts at a nonzero integer coordinate PiP_i, in meters, and runs away from you at the constant integer speed of SiS_i meters per second. A quail keeps running away even while you are chasing something else. You run at the constant integer speed of YY meters per second and can change direction instantly at any moment. Whenever you occupy the same point as a quail, that quail is caught, and catching it takes no extra time.

Passing a quail requires catching it first, so a quail that starts at a positive coordinate always runs to the right, and a quail that starts at a negative coordinate always runs to the left.

What is the minimum number of seconds needed to catch every quail?

Input

The first line contains the number of test cases TT. TT test cases follow. The first line of each test case contains two space separated integers YY, your speed, and NN, the number of quail. The next line contains the positions P1,P2,,PNP_1, P_2, \dots, P_N, and the line after that contains the speeds S1,S2,,SNS_1, S_2, \dots, S_N, each list space separated.

Limits

  • 1T1001 \le T \le 100
  • 2Y10002 \le Y \le 1000
  • 1N251 \le N \le 25
  • 107Pi107-10^7 \le P_i \le 10^7, Pi0P_i \ne 0
  • 1Si<Y1 \le S_i < Y

Output

For each test case, print one line in the form Case #x: y, where xx is the test case number starting from 1 and yy is the minimum number of seconds needed to catch every quail.

Round yy to six decimal places and always print six digits after the decimal point. When the discarded part is exactly one half, round up. Every exact answer in the input data is at least 10910^{-9} away from a rounding boundary.

Hint

In test case 1 of the first example, you run to the left and catch all three quail at the same moment, 12 meters to the left of your starting point. That takes 3 seconds.

One optimal strategy for test case 2 is this. Run left and catch the second quail at coordinate 2-2 after one second, then turn around and run right for four more seconds to catch the first quail at coordinate 66.