Let's say that three segments on a plane form a K-shaped figure if:
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| AB,CD,CE | AB,CD,CE | AB,CD,CE | AB,CD,CE | AB,CD,CE | AB,CD,EF | AB,AC,AD |
| Valid K-shaped figures | Invalid K-shaped figures |
You are given a collection of n segments on the plane. Find the number of triples of segments from this collection that form a K-shaped figure.
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤3333). The description of the test cases follows.
The first line of each test case contains a single integer n --- the number of segments (3≤n≤1000).
The i-th of the following n lines contains four integers x_i,1, y_i,1, x_i,2, y_i,2 --- the coordinates of endpoints of the i-th segment (−106≤x_i,1,y_i,1,x_i,2,y_i,2≤106). All segments have positive lengths. Some segments may coincide.
It is guaranteed that the sum of n over all test cases does not exceed 104.
For each test case, print a single integer --- the number of triples of segments that form a K-shaped figure.