#P12109. [NWRRC2024] Eight-Shaped Figures

[NWRRC2024] Eight-Shaped Figures

Description

Let's say that two circles on a plane form an 8-shaped figure\textit{8-shaped figure} if they touch each other, but neither of them lies inside the other one.

You are given a collection of nn circles on the plane. No two circles have more than one common point. In other words, no two circles intersect twice or coincide, but they can touch or lie one within another.

Find the number of pairs of circles from this collection that form an 8-shaped figure.

Input Format

Each test contains multiple test cases. The first line contains the number of test cases tt (1t1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains a single integer nn, denoting the number of circles (2n21052 \le n \le 2 \cdot 10^5).

The ii-th of the following nn lines contains three integers xix_i, yiy_i, and rir_i, denoting the coordinates of the center of the ii-th circle and its radius (109xi,yi109-10^9 \le x_i, y_i \le 10^9; 1ri1091 \le r_i \le 10^9). No two circles intersect twice or coincide, but they can touch or lie one within another.

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5.

Output Format

For each test case, print the number of pairs of circles that form an 8-shaped figure.

2
5
1 1 1
1 3 1
3 1 1
3 3 1
6 7 4
6
-3 0 3
-2 0 2
-1 0 1
1 0 1
2 0 2
3 0 3
5
9