Dynamic Frog

With the increased use of pesticides, the local streams and rivers have become so contaminated that it has become almost impossible for the aquatic animals to survive.

Frog Fred is on the left bank of such a river. n rocks are arranged in a straight line from the left bank to the right bank. The distance between the left and the right bank is d meters. There are rocks of two sizes. The bigger ones can withstand any weight but the smaller ones start to drown as soon as any mass is placed on it. Fred has to go to the right bank where he has to collect a gift and return to the left bank where his home is situated.

He can land on every small rock at most one time, but can use the bigger ones as many times as he likes. He can never touch the polluted water as it is extremely contaminated.

Can you plan the itinerary so that the maximum distance of a single leap is minimized?


The first line is the number of test cases t (t < 100). Each case starts with a line containing two integers n (0n100) and d (1d109). The next line gives the description of the n stones. Each stone is defined by s-m. s indicates the type Big (B) or Small (S) and m (0 < m < d) determines the distance of that stone from the left bank. The stones will be given in increasing order of m.


For each test case print the case number followed by the minimized maximum leap.

Time limit 1 second
Memory limit 128 MiB
Input example #1
1 10
1 10
2 10
B-3 S-6
Output example #1
Case 1: 5
Case 2: 10
Case 3: 7
Input example #2
6 50
S-2 B-14 S-20 S-26 B-38 S-43
Output example #2
Case 1: 18