Cube#7210

Cube

1 second
64 megabytes
Hard

The distance on the surface of a polyhedron between two points is defined as the shortest length of a broken line connecting these two points, such that all segments of the line lie on the surface of the polyhedron.

Consider a cube whose vertices in the Cartesian coordinate system have coordinates or a certain natural number , with a \leq 15.

Write a program that calculates the square of the distance along the surface of the cube between two points with integer coordinates: the first of which lies on a face of the cube in the -plane, and the second is any point on the surface of the cube.

Input

The first line contains two natural numbers and .

For each from to , the (j+1)-th line contains non-negative integers. The first three numbers are the coordinates of the first point (abscissa , ordinate , applicate ), which lies on a face of the cube in the -plane. The next three numbers are the coordinates of the second point, which is any point on the surface of the cube.

Output

For each input line starting from the second, output the square of the shortest path length along the surface of the cube connecting the pair of points specified in that line.

Examples

Example 1

Loading
Loading