Triangle Areas

Given N, M, A, find three lattice points in an N by M grid forming a triangle of area exactly A/2, printing the lexicographically smallest coordinate sequence or IMPOSSIBLE.

Medium6GeometryMathBrute forceImplementationInterviewNo attempts yetTime limit5sMemory limit512 MB

Problem

Ten-year-old Tangor has just learned how to compute the area of a triangle. He is amazed that there are so many ways to do it, and he convinced himself that when all three vertices have integer coordinates, the area is always an integer or half of an integer.

Today he works in the opposite direction. Instead of drawing a triangle and computing its area, he fixes an integer AA and tries to draw a triangle of area exactly A/2A/2. He places vertices only on the lattice points of his graph paper.

The sheet of graph paper is divided into an NN by MM grid of square cells. If you put a coordinate system on the paper, the points available as vertices are the points (x,y)(x, y) with integers xx and yy such that 0xN0 \le x \le N and 0yM0 \le y \le M.

Given the integers NN, MM, and AA, decide whether three lattice points form a triangle of area exactly A/2A/2, and if they do, report those three points.

Input

The first line contains the number of test cases CC in the input.

Each of the next CC lines contains three integers NN, MM, and AA.

Limits

  • 0C10000 \le C \le 1000
  • 1A1081 \le A \le 10^8
  • 1N501 \le N \le 50
  • 1M501 \le M \le 50

Output

For each test case, print one line. If no triangle satisfies the condition, print

Case #k: IMPOSSIBLE

where k is the case number, starting from 1. Otherwise print

Case #k: x1 y1 x2 y2 x3 y3

where (x1,y1)(x_1, y_1), (x2,y2)(x_2, y_2), and (x3,y3)(x_3, y_3) are three lattice points that form a triangle of area A/2A/2.

Several triangles can satisfy the condition, so the output is pinned to one of them. Read the six printed numbers as the sequence (x1,y1,x2,y2,x3,y3)(x_1, y_1, x_2, y_2, x_3, y_3) and print the lexicographically smallest such sequence. A lexicographic comparison looks at the first position where two sequences differ. The three points may be written in any order, so in the smallest sequence they appear sorted by (x,y)(x, y).