Sculpture

Time limit1sMemory limit128 MB

Problem

Imagine a box made of copper plate. Imagine a second one intersecting the first, and several others intersecting one another (or not). That is how a sculptor builds his sculptures. In fact he does not build them himself; he only makes the design, and the actual construction is contracted out to a construction company.

To calculate the construction cost, the company needs the total area of copper plate involved. Parts of a box that are hidden inside another box are, of course, not made of copper (copper is expensive, and prices keep rising).

After construction, the whole piece is plunged into a bath of chemicals. To keep the bath from overflowing, the company also needs the total volume of the construction.

Given a construction that is a collection of boxes, compute its total copper-plate area and its total volume.

Some designs are connected and some are not; either way, we want the total area and the total volume. The boxes may completely enclose a region of space that belongs to none of them. Because the liquid cannot reach that region, its volume must be added to the total volume. Copper plate bordering such an enclosed region is superfluous, so it does not add to the area.

Input

The first line contains a single positive integer: the number of test cases, at most $100$. Each test case is given as follows:

  • One line with an integer $n$ ($1 \le n \le 50$): the number of boxes.
  • $n$ lines, each with six positive integers $x_0, y_0, z_0, x, y, z$ ($1 \le x_0, y_0, z_0, x, y, z \le 500$). The point $(x_0, y_0, z_0)$ is the corner of the box with the smallest coordinates, and $x, y, z$ are its side lengths along the respective axes. All lengths are in centimeters, and every box has edges parallel to the coordinate axes.

Output

For each test case, print one line with two integers separated by a single space: the total amount of copper plate needed (in square centimeters) and the total volume (in cubic centimeters).