Under construction

Still being built. Things may change

Triangle Puzzle

Time limit1sMemory limit512 MB

Summary
Count the sets of four triangles that can be rotated and moved, but not reflected, to form one large triangle with a piece at each corner and one in the center.
Level

Medium7 of 10

Topics
Geometry, Brute force, Implementation
Solved
No attempts yet

Statement

The puzzle consists of nn triangles. To solve it, choose four of them and assemble a large triangle using the scheme below. The triangles must not overlap, and together they must form one triangle. Exactly one of the chosen triangles sits at each of the three corners, and one triangle sits in the center. The triangles lie on a table. You may rotate and move them freely, but you may not reflect them. Find all distinct sets of four triangles from which the large triangle can be built this way. Two sets are different if some triangle belongs to one set but not to the other.

Input

The first line contains a single integer tt, the test number. The second line contains nn, the number of triangles in the puzzle (4≤n≤304 \le n \le 30). Each of the next nn lines describes one triangle by the coordinates of its three corners, listed counterclockwise. All coordinates are integers with absolute value at most 10510^5. No triangle is degenerate. In the initial layout, the triangles may overlap.

Output

On the first line, print the number of sets of four triangles from which the large triangle can be built. Then print the sets, one per line, as the numbers of their triangles. Triangles within a set may be printed in any order, and the sets may be printed in any order.

Hints

In the first example, the four given triangles form one large triangle, and no triangle needs to be rotated. In the second example, all triangles are the same right triangle whose two legs have length 11. Any four of them form the large triangle.

Examples2

  1. Example 1

    Input
    1
    4
    0 0 6 2 1 2
    0 0 5 0 6 3
    0 0 3 1 1 3
    0 0 6 3 3 6
    
    Expected output
    1
    1 2 3 4
    
  2. Example 2

    Input
    2
    6
    0 0 1 0 1 1
    0 1 0 0 1 0
    -1 0 0 0 0 1
    1 1 0 1 1 0
    -1 0 0 -1 0 0
    0 0 1 1 0 1
    
    Expected output
    15
    1 2 3 4
    1 2 3 5
    1 2 3 6
    1 2 4 5
    1 2 4 6
    1 2 5 6
    1 3 4 5
    1 3 4 6
    1 3 5 6
    1 4 5 6
    2 3 4 5
    2 3 4 6
    2 3 5 6
    2 4 5 6
    3 4 5 6