eolymp
bolt
Try our new interface for solving problems
Problems

Alchemy

Alchemy

Since the days of yore alchemy has been studied and practiced. The practice makes alchemists able to transmute materials into other forms. Transmuting materials requires drawing a transmutation circle on the ground. A little known fact about transmutation circles is they can be drawn inside other transmutation circles. By activating certain configurations in the correct order, more powerful transmutations can be produced. Activating circles incorrectly can have drastic effects on the alchemist's body.

A young alchemist named Nicholas Flamel would like to learn the ways of alchemy. He has drawn several configurations of transmutation circles on the ground. When a circle is activated it burns bright red representing the element of fire. The activation itself produces no extra energy. The secret is when an outer transmutation circle is activated. When this occurs, all already active circles in the area of the activated circle quickly change to their respective complement elements. Fire changes to a cool blue representing water. Circles that were blue for water will burn fiery red once again. This change can either create or drain energy from the transmutation. Beware, energy can go negative at any time by temporarily draining the alchemist's life force (but the spell continues to work just fine).

Nicholas wants to get as much out of his transmutations as possible. To do so requires him to activate all his circles in an order that releases the most energy. Determine the maximum amount of energy that can be released.

Input

Starts with a single line with the number of test cases t between 1 and 100 inclusive. For each set of transmutation circles there will be a line with a number n (1n2000). This represents the number of transmutation circles. The next n lines contain spaced-separated integers x y a b. The first three integers represent the coordinates and radius of the circle, while the last two represent the energy release for going from fire to water (A), and water to fire (B) (-10000x, y10000, 1r10000, -500a, b500).

No two circles will intersect or touch.

Output

For each set of transmutation circles print a single integer representing the maximum energy that can be produced by activating the circles. On the following line print the permutation of the input circles that can produce that energy. If multiple permutations exist, print the one that comes first lexicographically.

Time limit 4 seconds
Memory limit 128 MiB
Input example #1
1
8
0 0 100 -100 -100
0 0 50 -10 -10
0 0 10 -100 500
0 0 1 100 100
1000 1000 100 -1 1
1000 1000 50 -1 1
1000 1000 10 -1 1
1000 1000 1 -1 1
Output example #1
700
4 3 1 2 5 6 7 8
Source 2014 ACM North America - Pacific Northwest, Дивизион 1, Задача B