#K36227. Cube Carving

    ID: 25708 Type: Default 1000ms 256MiB

Cube Carving

Cube Carving

You are given a cube with side length \(n\) from which a rectangular cuboid has been carved out. The cuboid is defined by the coordinates of two opposite corners, \((x_1, y_1, z_1)\) and \((x_2, y_2, z_2)\). Your task is to compute the remaining volume of the cube after the cuboid has been removed.

The volume of the cube is given by \(n^3\) and the volume of the carved cuboid is given by \((x_2 - x_1) \times (y_2 - y_1) \times (z_2 - z_1)\). The remaining volume is therefore:

[ V_{remaining} = n^3 - (x_2 - x_1)(y_2 - y_1)(z_2 - z_1) ]

If the carved cuboid occupies the whole cube then the remaining volume will be 0.

inputFormat

The first line of input contains a single integer \(T\) representing the number of test cases. Each test case consists of a single line containing 7 space-separated integers:

  • \(n\): the side length of the cube.
  • \(x_1\), \(y_1\), \(z_1\), \(x_2\), \(y_2\), \(z_2\): coordinates of the opposite corners of the cuboid.

Note: It is guaranteed that \(x_2 \geq x_1\), \(y_2 \geq y_1\), and \(z_2 \geq z_1\).

outputFormat

For each test case, output a single line containing the remaining volume of the cube after the specified cuboid has been carved out.

## sample
3
10 1 1 1 3 3 3
8 2 2 2 4 4 4
5 0 0 0 2 2 2
992

504 117

</p>