Under construction

Still being built. Things may change

Turning gears (hard)

Interview

Time limit2sMemory limit1024 MB

Summary
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.
Level

Medium5 of 10

Topics
Graph, BFS, Geometry
Solved
No attempts yet

Problem

Jano the mechanic has many gears of different sizes. He took nn of them and assembled a complicated machine. He wants to know whether gear number nn rotates when he turns gear number 1, and if so, how fast.

The gears are numbered 1 to nn, and all of them lie in the same plane.

Gear ii is a circle with center (xi,yi)(x_i, y_i) and radius rir_i. 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 r1r_1 and r2r_2, and the first turns at v1v_1 revolutions per second, the second turns in the opposite direction at v2=v1r1r2v_2 = \frac{v_1 r_1}{r_2} 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 nn rotate?

Input

The first line contains an integer tt, the number of test cases. Each test case is preceded by a blank line.

Each test case starts with nn (2≤n≤1 0002 \le n \le 1\,000), the number of gears. The next nn lines describe gears 11 to nn. Line ii contains three integers xix_i, yiy_i, and rir_i. You may assume 0≤xi,yi≤50 0000 \le x_i, y_i \le 50\,000 and 1≤ri≤1 0001 \le r_i \le 1\,000.

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 n−1n-1 pairs of directly linked gears.

Output

For each test case, print one line with the speed of gear nn as a reduced fraction p/qp/q, where the greatest common divisor of pp and qq is 1. Follow it with the direction, either clockwise or counterclockwise. If gear nn 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.

Examples1

  1. Example 1

    Input
    3
    
    3
    0 0 2
    4 0 2
    7 0 2
    
    5
    0 10 6
    20 9 5
    12 9 7
    8 0 5
    22 0 5
    
    6
    8 6 4
    10 13 5
    13 20 5
    3 0 3
    15 1 5
    0 4 3
    
    Expected output
    1/1 clockwise
    6/5 counterclockwise
    does not rotate