K-Shaped Figures
Time limit3sMemory limit1024 MB
Count triples of segments where two share an endpoint lying strictly inside the third segment, with both on the same side of it.
Problem
Time limit: 3000 ms. Memory limit: 1024 MB.
Let's say that three segments on a plane form a K-shaped figure if:
- two of them share a common endpoint;
- this common endpoint lies strictly inside the third segment;
- these two segments are located on the same side with respect to the third one;
- all three segments are pairwise not collinear.
You are given a collection of segments on the plane. Find the number of triples of segments from this collection that form a K-shaped figure.
Input
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains a single integer , the number of segments ().
The -th of the following lines contains four integers , , , , the coordinates of the endpoints of the -th segment (). All segments have positive lengths. Some segments may coincide.
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, print a single integer: the number of triples of segments that form a K-shaped figure.






