#P17221. [ICPC 2017 Nanning R] Resonators

[ICPC 2017 Nanning R] Resonators

Problem Description

:::align{center} :::

The Sun-glade Isle as a portal is an important military fortress, located in the East China Sea. Several finest agents climbed onto the island successfully. They captured the portal and declared the victory of the battle, temporarily.

To reinforce the portal, they deployed NN resonators around the portal. The centre of the portal is located at (0,0)(0, 0). A resonator occupies a circular area. The centre of the ii-th one is (xi,yi)(x_i, y_i) and its radius is rir_i. These circular areas are likely to overlap.

The total defense capability is the sum of squared distances to the centre of the portal (0,0)(0,0) from the locations which be occupied by at least one resonator. That is say that if there is a sufficient small region occupied by at least one resonator, this region would offer the defense capability up to the product of the area, and the squared distance to the centre (0,0)(0, 0).

If we suppose Ω\Omega as the union of all resonators which is the union of several circles. The total defense capability of this portal is actually the result of the following integral:

$$\int_{\Omega} |v|^2 ds = \int_{\Omega}{(x^2 + y^2)} dx dy.$$

Here is your mission, as a super leader the Intel. Compute the total defense capability of this portal.

Input Format

The input contains several test cases and the first line of input gives the number of test cases which is up to 5050.

For each test case, the first line contains the integer N(N≤1000)N (N \le 1000) which is the total number of resonates deployed. The following NN lines describe these resonators and the ii-th line contains three integers xix_i, yiy_i and rir_i, where ∣xi∣,∣yi∣≤100|x_i|, |y_i| \le 100 and 1≤ri≤51 \le r_i \le 5.

Output Format

For each test case output the defense capability rounding up to three decimal places.

3
1
0 0 1
2
0 0 1
1 0 1
3
0 0 1
1 0 1 
0 1 1
1.571
5.704
9.668

Hint

For the first test case in the sample, the answer if

$$\int_{-1}^{1} \int_{ \sqrt{1-x^2} }^{\sqrt{1-x^2}} (x^2+y^2) = \frac{\Pi}{2} \approx 1.5708$$

The answer of the second test case is the sum of

$$\int_{-1}^{1/2} \int_{ \sqrt{1-x^2}}^{\sqrt{x-x^x}} (x^x+y^2)dydx \approx 1.15545$$

and

$$\int_{1/2}^{2} \int_{ \sqrt{1-(x-1)^2} }^{\sqrt{1-(x-1)^2}} (x^2+y^2)dydx \approx 4.54888$$