This page is still under construction.

Parts of this page are still being built. What you see may change.

Shortest Fence

Time limit1sMemory limit128 MB

Summary
Enclose up to 100 disjoint circles with the shortest closed fence and print its length rounded to five decimals.
Level

Medium7 of 10

Topics
Geometry, Sorting
Solved
No attempts yet

Problem

Your garden holds trees and goats. To keep the goats off the trees you decide to build one fence that encloses every tree, and you want that fence to be as short as possible.

Seen from above, each tree is a circle in the plane. The fence is a closed curve that keeps every tree inside it, and it touches some or all of the trees. Find the smallest possible length of such a fence.

Input

The first line contains the number of test cases TT. (1≤T≤2501 \le T \le 250)

Each test case is given in N+1N + 1 lines. The first line contains the number of trees in the garden NN. (1≤N≤1001 \le N \le 100) Each of the next NN lines contains three integers XX, YY and RR separated by spaces. XX and YY are the coordinates of the centre of a tree and RR is its radius.

XX, YY and RR are integers between 11 and 10001000, inclusive. No two trees in the input touch or overlap.

Output

For each test case, print on one line the minimum length of a fence that surrounds every tree. Round the value at the sixth decimal place and always print five digits after the decimal point.

Examples1

  1. Example 1

    Input
    4
    5
    3 3 2
    12 12 2
    3 12 2
    12 3 2
    8 8 1
    3
    3 3 2
    9 3 2
    6 7 2
    2
    5 5 1
    10 10 2
    1
    5 5 10
    
    Expected output
    48.56637
    28.56637
    23.70857
    62.83185