Sail Shreds 4
Time limit2sMemory limit512 MB
Translate each triangle without rotation so that the triangles exactly tile an X by Y rectangle, with no overlaps and no part outside.
Problem
During the recent two-day storm, a group of sailors shipwrecked on a desert island in the Mediterranean sea. Since their radio is broken, they cannot call for help and their only chance of survival is escaping on a raft. However, they need a sail to power the raft. Luckily, they recovered the main sail from the wrecked ship, but it is torn to several shreds. Hence, they have to sew the shreds together to obtain the original sail.
The sailors quickly realized that each of the shreds is a triangle. Because there were stripes on the sail, it was easy to identify the correct orientation of its triangular parts. The shreds must keep their orientations. Otherwise the sail would be less resistant to wind and might be torn again. They spent several hours looking for the original arrangement without success. They think a computer can help, so they asked you.
You are given the plane coordinates of the vertices of each triangular shred and the dimensions of the original sail, which was a rectangle given by two integers and . Your task is to move the shreds (without rotation) to reconstruct the original sail (see the figure). In particular, the triangles must be moved so that:
- the whole rectangular area is covered,
- no two triangles intersect, that is, no point lies in the interiors of two different triangles, and
- no triangle has any part outside the rectangle.
You may assume that a solution exists for each input. In particular, the sum of the areas of the shreds equals the area of the original sail. Several shreds may have the same shape.

Input
The first line contains three integers , , and , separated by single spaces. is the width and is the height of the original sail, with . is the number of triangular shreds, with .
The next lines describe the triangles. The -th line contains six integers , , , , , and , separated by single spaces. These describe the three vertices , , and of the -th triangle, where is at , is at , and is at . All coordinates satisfy coordinate .
The position of a triangle in the input is irrelevant. Translating a triangle to another position gives the same set of shreds.
Output
Output exactly lines. The -th line contains two integers and , separated by a single space. These are the coordinates of the point after the -th shred is moved to its place. All three conditions in the problem must hold. The lower left corner of the sail is at and the upper right corner is at , as shown in the figure.