Counting triangles 

Background

Acme Counting Machines has hired you as a consultant to finish their TCM-2000 project. The TCM-2000 is a machine for counting triangles in pictures by means of a video camera attached to a computer. They have already done the easy part of preprocessing the picture to extract the edges and convert the image into a list of segments. Your job is to write a program to count all the triangles defined by those segments.

The Problem

Your program will receive a list segments and it has to return the number of triangles in the figure. The segments given to the program may intersect and may overlap (totally or partially). For example, given the following figure:

Your program may receive the following list of segments: AB, AD, AF, BC, BF, CD, CE, CF, DE and DF (it can receive a different input for that same figure). Then, it will have to count the 9 triangles present in the figure, namely: ABC, ABF, ACD, ADC, ADF, BCD, BCF, CDE and CDF.

Hint: remember to allow some tolerance if you ever have to compare floating-point numbers.

The Input

The input format is as follows:

An integer in a single line which says the number of figures that your program will have to process. Then, for each figure there will be:

The Output

The output consists of one line for each figure, with a single integer number each: the number of triangles found.

Sample Input

2
10
0 0 0 1
0 0 0.5 0.5
0 0 1 0
0 1 0.5 0.5
0 1 0.5 1.5
0 1 1 1
0.5 0.5 1 0
0.5 0.5 1 1
0.5 1.5 1 1
1 0 1 1
8
0 0 1 0
0 0 0 1
0 1 1 0
1 0 1 1
1 1 0.5 1.5
0 1 0.5 1.5
0 0 1 1
0 1 1 1
  

Sample Output

9
9