Stake Coordinate Reconstruction

Time limit1sMemory limit128 MB

Problem

Stakes have been driven into a grassy field where a new math building will go, and you must reconstruct their coordinates.

Surveying shows that the first three stakes form a right-angled triangle whose legs are each $1$ metre long and whose hypotenuse is $\sqrt{2}$ metres long. These three stakes are placed at coordinates $(0,0)$, $(0,1)$, and $(1,0)$; that is, stakes $1$, $2$, and $3$ are at $(0,0)$, $(0,1)$, and $(1,0)$ respectively. All of the other stakes also land exactly on lattice points (points with integer coordinates).

Given the triangle measurements, determine the coordinates of every stake.

Input

The input consists of several test cases. The first line of each test case contains two integers $n$ and $m$, each at least $1$ and at most $1000$. The integer $n$ is the number of lines that follow, and $m$ is the number of stakes. The stakes are numbered $1$ to $m$, and all stakes are at distinct locations. Each stake's $x$ and $y$ coordinates are between $-1000000$ and $1000000$ inclusive.

Each of the following $n$ lines contains exactly six integers $a$, $b$, $c$, $x$, $y$, $z$. The integers $a$, $b$, $c$ are the numbers of three stakes, always listed in counter-clockwise order: moving from stake $a$ to stake $b$ to stake $c$, you turn left at stake $b$. The value $x$ is the square of the distance from stake $a$ to stake $b$, $y$ is the square of the distance from stake $b$ to stake $c$, and $z$ is the square of the distance from stake $c$ to stake $a$.

Every stake appears in at least one line. Moreover, for every pair of stakes $a$, $b$ there is a subset of the triangles forming a sequence $T_1, T_2, \ldots, T_n$ such that $T_i$ and $T_{i+1}$ share two vertices for all $0 < i < n$, with $a$ a vertex of $T_1$ and $b$ a vertex of $T_n$. The last line of input is $0\ 0$; these zeros are not values of $n$ and $m$ and must not be processed as such.

Output

For each test case, output exactly $m$ lines describing stakes $1$ to $m$ in order. Each line contains two integers, the $x$ and $y$ coordinates of that stake, separated by a space. The first three lines of output for each test case are always:

0 0
0 1
1 0