Under construction

Still being built. Things may change

Intersection Graph

Time limit1sMemory limit256 MB

Summary
For two axis-aligned boxes, list every nonempty boundary intersection as a point, curve, or surface and output its endpoints and incidences.
Level

Hard8 of 10

Topics
Geometry, Implementation, Brute force
Solved
No attempts yet

Problem

Innokentiy still enjoys writing geometric algorithms, but he has moved from triangular meshes to solid bodies. He wants to write an algorithm that builds the intersection graph of two bodies, which is needed, for example, to run a boolean operation on those bodies. Only the boundaries of the bodies are considered when building the graph; their interior volumes are ignored. Innokentiy knows that building the intersection graph of two arbitrary bodies is a difficult task in CAD. He has decided to start with a simpler case: learning to build the intersection graph of two boxes, AA and BB.

A box (usually called an axis-aligned box) is a rectangular parallelepiped whose sides are parallel to the coordinate axes. The boundary of a box consists of topological elements of three types:

  • V: a vertex, which is geometrically a point;
  • E: an edge, which is a line segment;
  • F: a face, which is a rectangle.

Each box has 8 vertices, 12 edges, and 6 faces.

For this problem, an edge and a face are represented by the corresponding point sets without boundary points. Thus an edge is a line segment that does not contain its endpoints, and a face is a rectangle that does not contain its corners or sides. Under this definition, the topological elements share no points, and together they form exactly the entire boundary of the box.

An intersection graph consists of interrelated intersection elements, defined as follows. Consider every pair consisting of a topological element uu of box AA and a topological element vv of box BB (676 pairs in total). For each pair (u,v)(u,v), take the intersection of the two sets. If the intersection is non-empty, it defines an intersection element, which has one of three types:

  • p: a point, a single point;
  • c: a curve, a set of points forming a line segment;
  • s: a surface, a set of points forming a rectangle.

The intersection graph consists of all intersection elements obtained in this way.

The intersection elements are interconnected. For each intersection curve, the two intersection points at its ends are stored. For each intersection point, a list of intersection curves incident to that point is stored. An intersection curve is incident only to its endpoints and to no other intersection points. For each intersection surface, the set of intersection curves on its boundary (and therefore bounding it) is stored.

Input

The first line of the input file contains a single integer TT, the number of test cases (1≤T≤50001 \le T \le 5000). It is followed by TT blocks.

Each block consists of two lines. The first line defines box AA, and the second line defines box BB. A box is described by six integers x1,y1,z1,x2,y2,z2x_1, y_1, z_1, x_2, y_2, z_2 whose absolute values do not exceed 10310^3. The numbers x1,y1,z1x_1, y_1, z_1 are the coordinates of the minimal vertex, and x2,y2,z2x_2, y_2, z_2 are the coordinates of the maximal vertex (x1<x2x_1 < x_2, y1<y2y_1 < y_2, z1<z2z_1 < z_2).

Output

The output file must contain the TT intersection graphs for the test cases in the input file. After each intersection graph, print === on a separate line. All numbers in the output file must be integers.

The description of an intersection graph contains many links between intersection elements and topological elements. To describe these links, assign a number (or index) to every element. All topological elements of box AA must be numbered from 11 to 2626 in any order. Likewise, all topological elements of box BB must be numbered from 11 to 2626 in any order. Also, all intersection elements must be numbered from 11 to KK in the order in which they appear in the output file, where KK is the total number of intersection elements.

The first line of an intersection graph description must contain three numbers: PP, the number of intersection points; CC, the number of intersection curves; and SS, the number of intersection surfaces. Naturally, P+C+S=KP+C+S=K. After that, describe the intersection elements in this order: first the PP intersection points, then the CC intersection curves, and finally the SS intersection surfaces, with one intersection element per line.

The description of each intersection element must begin with its index, followed by a three-letter code made by the following rule.

  1. The first letter is the type of the intersection element: p for a point, c for a curve, or s for a surface.
  2. The second letter is the type of topological element uu: V for a vertex, E for an edge, or F for a face.
  3. The third letter is the type of topological element vv.

Here uu and vv are the topological elements of boxes AA and BB, respectively, from which the intersection element was generated. Next, print two integers: the indices of uu and vv, in that order. Finally, print additional information depending on the type of the intersection element.

For an intersection point, also print its three coordinates, the number of intersection curves incident to it, and the list of indices of those curves. The indices of incident curves may be printed in any order.

For an intersection curve, also print the indices of the two intersection points at its ends. These two numbers may be printed in any order.

For an intersection surface, also print the number of intersection curves on its boundary and the list of their indices. The indices of the boundary curves may be printed in any order.

The numbers in the output file do not have to be separated by exactly one space. Several spaces in a row are allowed.

Hint

In the first test case, the boxes pass through each other at a corner. The intersection graph is drawn with bold lines. It consists of six points and six curves, hidden from the viewer by box BB. The indices of the intersection elements are shown.

In the second test case, the boxes share their bottom and front faces, which produces intersection surfaces 19 and 20 (they are not shown in the figure). All remaining elements are shown in bold, and their indices are given.

Examples1

  1. Example 1

    Input
    2
    0 0 0 5 4 3
    2 3 1 7 6 5
    0 2 6 10 8 9
    2 4 6 10 10 10
    
    Expected output
    6 6 0
    1  pFE  14 2  5 3 1  2  7 8
    2  pFE  16 4  2 4 1  2  9 10
    3  pEF  17 5  5 4 1  2  7 9
    4  pFE  22 10  2 3 3  2  11 12
    5  pEF  23 11  5 3 3  2  8 11
    6  pEF  25 13  2 4 3  2  10 12
    7  cFF  14 5   1 3
    8  cFF  14 11   1 5
    9  cFF  16 5   2 3
    10  cFF  16 13   2 6
    11  cFF  22 11   4 5
    12  cFF  22 13   4 6
    ===
    8 10 2
    1  pEV  6 3  10 4 6  3  9 10 13
    2  pVE  9 6  10 8 6  3  9 12 14
    3  pFV  5 1  2 4 6  2  10 11
    4  pEE  8 4  2 8 6  3  11 12 16
    5  pEE  23 12  10 4 9  3  13 15 17
    6  pVF  26 14  10 8 9  2  14 15
    7  pFE  22 10  2 4 9  2  17 18
    8  pEF  25 13  2 8 9  2  16 18
    9  cEE  6 6   1 2
    10  cFE  5 2   1 3
    11  cFE  5 4   3 4
    12  cEF  8 5   2 4
    13  cFE  14 12   1 5
    14  cEF  17 14   2 6
    15  cEF  23 14   5 6
    16  cFF  16 13   4 8
    17  cFF  22 11   5 7
    18  cFF  22 13   7 8
    19  sFF  5 5  4  9 10 11 12
    20  sFF  14 14  4  9 13 14 15
    ===