K-Shaped Figures

아직 제출이 없습니다시간 제한3초메모리 제한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.
AB,CD,CE\\{AB,CD,CE\\}AB,CD,CE\\{AB,CD,CE\\}AB,CD,CE\\{AB,CD,CE\\}AB,CD,CE\\{AB,CD,CE\\}AB,CD,CE\\{AB,CD,CE\\}AB,CD,EF\\{AB,CD,EF\\}AB,AC,AD\\{AB,AC,AD\\}
Valid K-shaped figuresInvalid K-shaped figures

You are given a collection of nn 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 tt (1t33331 \le t \le 3333). The description of the test cases follows.

The first line of each test case contains a single integer nn --- the number of segments (3n10003 \le n \le 1000).

The ii-th of the following nn lines contains four integers x_i,1x\_{i,1}, y_i,1y\_{i,1}, x_i,2x\_{i,2}, y_i,2y\_{i,2} --- the coordinates of endpoints of the ii-th segment (106x_i,1,y_i,1,x_i,2,y_i,2106-10^6 \le x\_{i,1}, y\_{i,1}, x\_{i,2}, y\_{i,2} \le 10^6). All segments have positive lengths. Some segments may coincide.

It is guaranteed that the sum of nn over all test cases does not exceed 10410^4.

출력

For each test case, print a single integer --- the number of triples of segments that form a K-shaped figure.