Under construction

Still being built. Things may change

Triangle Areas (Large)

Time limit5sMemory limit512 MB

Summary
Given N, M and A, print the canonical triangle (0,0), (N,1), (w,h) with area A/2, or IMPOSSIBLE when A exceeds N*M.
Level

Easy3 of 10

Topics
Geometry, Math, Implementation, Brute force
Solved
No attempts yet

Problem

Tangor is ten years old and has just learned how to compute the area of a triangle. He also worked out on his own that if all three vertices of a triangle have integer coordinates, the area is always an integer or half of an integer.

Today he is going the other way. Instead of measuring a triangle he already has, he picks an integer AA and tries to draw a triangle whose area is exactly A/2A/2. The vertices may sit only on the grid points of his graph paper.

The paper is divided into an NN by MM grid of square cells, and the only points he may use as vertices are the corners of those cells. Placing a coordinate system on the paper, a usable point is (x,y)(x, y) for integers xx and yy with 0≤x≤N0 \le x \le N and 0≤y≤M0 \le y \le M.

Given NN, MM and AA, find three grid points that form a triangle of area exactly A/2A/2, or report that no such triangle fits on the paper.

Input

The first line holds an integer CC, the number of test cases.

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

Constraints

  • 0≤C≤10000 \le C \le 1000
  • 1≤A≤1081 \le A \le 10^8
  • 1≤N≤100001 \le N \le 10000
  • 1≤M≤100001 \le M \le 10000

Output

Print one line for each test case.

Many different triangles can have the same area, so the answer is fixed to a single canonical triangle. Let kk be the case number, counted from 1.

If A>N×MA > N \times M, no triangle of area A/2A/2 fits on the paper. In that case print

Case #k: IMPOSSIBLE

Otherwise let h=⌈A/N⌉h = \lceil A / N \rceil and w=Nh−Aw = N h - A. These satisfy 1≤h≤M1 \le h \le M and 0≤w<N0 \le w < N, and the triangle with vertices (0,0)(0, 0), (N,1)(N, 1) and (w,h)(w, h) has area exactly A/2A/2. Print those vertices in that order:

Case #k: 0 0 N 1 w h

That is, print the six integers 00, 00, NN, 11, ww, hh separated by single spaces.

Examples2

  1. Example 1

    Input
    3
    1 1 1
    1 2 64
    10 10 1
    
    Expected output
    Case #1: 0 0 1 1 0 1
    Case #2: IMPOSSIBLE
    Case #3: 0 0 10 1 9 1
    
  2. Example 2

    Input
    2
    5 3 7
    4 4 16
    
    Expected output
    Case #1: 0 0 5 1 3 2
    Case #2: 0 0 4 1 0 4