Turning gears (hard)
InterviewTime limit2sMemory limit1024 MB
Given circles whose touching pairs form a tree, find the speed and direction of gear n when gear 1 turns clockwise at 1 revolution per second.
Problem
Jano the mechanic has many gears of different sizes. He took of them and assembled a complicated machine. He wants to know whether gear number rotates when he turns gear number 1, and if so, how fast.
The gears are numbered 1 to , and all of them lie in the same plane.
Gear is a circle with center and radius . All coordinates are integers. The center of each circle lies strictly outside all other circles.
When two circles intersect, their gears are linked. A single point of contact counts as an intersection. The size of the overlap does not matter.
A rotation is described by a speed in full revolutions per second and a direction, either clockwise or counterclockwise. If two linked gears have radii and , and the first turns at revolutions per second, the second turns in the opposite direction at revolutions per second.
This equation applies to every linked pair in the machine. If a gear would have to turn at two different speeds or in two different directions, it does not rotate at all.
Jano turns gear number 1 clockwise at 1 revolution per second. How does gear rotate?
Input
The first line contains an integer , the number of test cases. Each test case is preceded by a blank line.
Each test case starts with (), the number of gears. The next lines describe gears to . Line contains three integers , , and . You may assume and .
Each test case also satisfies these guarantees. There are at most 200 gears. All gears are directly or indirectly linked to gear 1. There are exactly pairs of directly linked gears.
Output
For each test case, print one line with the speed of gear as a reduced fraction , where the greatest common divisor of and is 1. Follow it with the direction, either clockwise or counterclockwise. If gear does not rotate, print does not rotate instead.
Hints

In the first test case, gears 1 and 2 touch at a single point, and that still counts as linked. The answer is printed as 1/1. The denominator is always printed, so 2/2 and 1 are both rejected.
In the second test case:
- Gear 1 turns clockwise at 1 revolution per second.
- Gear 3 is linked to gear 1, so it turns counterclockwise at 6/7 revolutions per second.
- Gears 2 and 4 are linked to gear 3, so both turn clockwise. They both have radius 5, so each turns at 6/5 revolutions per second.
- Gear 5 is linked to gear 2, so it turns counterclockwise. Gears 2 and 5 have the same radius, so gear 5 also turns at 6/5 revolutions per second.
The third test case shows one of the two reasons the answer can be does not rotate.