Cruise Control (Large)

Decide whether cars with fixed speeds on a two-lane road can change lanes to avoid collisions forever, and otherwise report the latest safe time as a fraction.

Medium7GraphSortingSimulationMathNo attempts yetTime limit5sMemory limit512 MB

Problem

Cruise control keeps a car at a constant speed while the driver only steers. The driver can of course switch it off to avoid a collision.

This problem uses a one way road with two lanes and NN cars driving on it with cruise control on. Every car is 5 meters long and moves at its own constant speed. A car can change lanes at any moment as long as the change does not cause a collision with another car. Two cars that merely touch do not count as a collision. A lane change is instantaneous and does nothing except move the car to the other lane. Even though a lane change is instantaneous, two cars driving side by side cannot exchange places by changing lanes at the same time.

Decide whether all of the cars can keep their given speeds forever without a collision, changing lanes as often as they like, or whether somebody eventually has to switch cruise control off. If somebody has to, report the longest time they can all drive before that moment.

Input

The first line contains the number of test cases TT.

The first line of each test case contains the number of cars NN. Each of the next NN lines describes one car and contains a character CiC_i followed by two integers SiS_i and PiP_i. CiC_i is the lane the car starts in, L for the left lane and R for the right lane. SiS_i is the speed of the car in meters per second. PiP_i is the distance in meters from a fixed line drawn across the road to the rear end of the car. Every car drives away from that line, and no car is behind it.

  • 1T301 \le T \le 30
  • 1N501 \le N \le 50
  • 1Si10001 \le S_i \le 1000
  • 0Pi100000 \le P_i \le 10000
  • CiC_i is either L or R.
  • The cars do not collide at the start, that is, two cars ii and jj that start in the same lane satisfy PiPj5|P_i - P_j| \ge 5.

Output

For each test case print one line in the form Case #x: y, where xx is the test case number starting from 1. yy is Possible if all of the cars can keep their given speeds forever, and otherwise yy is the maximum number of seconds they can drive before somebody has to change speed.

Print the time exactly, as an irreducible fraction rather than a decimal. If the answer is p/qp/q with q1q \ge 1 and gcd(p,q)=1\gcd(p, q) = 1, print p/q when qq is at least 2, and print p alone when qq is 1. Print 0 when the answer is 0.

Notes

In the first case of the example the faster car moves to the right lane and passes the slower one without trouble. In the second case the two cars driving side by side at 100 meters per second catch the car going 50 meters per second after 10 seconds. Both lanes are blocked at that moment, so somebody has to change speed.