Server Time: Wed Feb 26, 2020 1:53 pm
 Welcome ( logout )
J - Jumping Frogs
 PDF (English) Ranklist
 Time Limit: 2 second(s) Memory Limit: 32 MB

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?

# Input

Input starts with an integer T (≤ 100), denoting the number of test cases.

Each case starts with a line containing two integers N (0 ≤ N ≤ 100) and D (1 ≤ D ≤ 109). 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.

# Output

For each case of input, print the case number and the minimized maximum leap.

# Output for Sample Input

3

1 10

B-5

1 10

S-5

2 10

B-3 S-6

Case 1: 5

Case 2: 10

Case 3: 7

Problem Setter: Sohel Hafiz
Special Thanks: Jane Alam Jan
 Developed and Maintained by JANE ALAM JAN Copyright © 2012 LightOJ, Jane Alam Jan