Under construction

Still being built. Things may change

3D Printing

Interview

Time limit5sMemory limit1024 MB

Summary
For each test case, choose four ink amounts no larger than every printer's supply that sum to exactly 10^6, or report IMPOSSIBLE.
Level

Easy3 of 10

Topics
Greedy, Implementation
Solved
No attempts yet

Problem

You are a member of the executive committee for the Database Design Day festivities. You are in charge of promotions and want to print three D's to make a logo for the contest. You may print them in any color, but all three must be printed in the same color.

You have three printers, and you will use each one to print one of the D's. Every printer uses ink from four separate cartridges, one each for cyan, magenta, yellow, and black, to form a color. For these printers, a color is uniquely defined by four non-negative integers cc, mm, yy, and kk, which give the number of units of cyan, magenta, yellow, and black ink needed to make the color.

Printing one D requires exactly 10610^6 units of ink. For example, printing a D in pure yellow uses 10610^6 units of yellow ink and 0 units from every other cartridge. Printing a D in Code Jam red uses 0 units of cyan ink, 500000 units of magenta ink, 450000 units of yellow ink, and 50000 units of black ink.

To print a color, a printer must have at least the required amount of ink in each of its four color cartridges. Given the number of ink units each printer has in each cartridge, output any color, defined as four non-negative integers that sum to 10610^6, such that all three printers have enough ink to print it.

Input

The first line of the input gives the number of test cases, TT. TT test cases follow. Each test case consists of three lines. The ii-th line of a test case contains four integers CiC_i, MiM_i, YiY_i, and KiK_i, the number of ink units in the ii-th printer's cartridges for cyan, magenta, yellow, and black, respectively.

Output

For each test case, output one line containing Case #x: r, where xx is the test case number starting from 1. If no color can be printed by all three printers, rr is IMPOSSIBLE. Otherwise, rr must be cc mm yy kk, where cc, mm, yy, and kk are non-negative integers that sum to 10610^6 and satisfy c≤Cic \le C_i, m≤Mim \le M_i, y≤Yiy \le Y_i, and k≤Kik \le K_i for all ii. If there are multiple solutions, you may output any one of them.

Hint

Sample Case #1 is the image above. The proposed color uses all the ink in the first printer's cyan, magenta, and yellow cartridges and all the ink in the last printer's black cartridge. No additional unit could be used from any of the four ink colors, so the sample output is the only possible output for this case.

In Sample Case #2, magenta is the only color that both the first and second printers have, so the only chance is to use 10610^6 units of magenta. Unfortunately, the third printer does not have quite enough, so this case is impossible.

In Sample Case #3, other correct outputs include 400000 100000 100000 400000, 300000 0 0 700000, and 350000 140000 160000 350000, among many others. 300000 140000 160000 700000 would not be valid because, even though all printers have enough ink for it, the total number of ink units must be exactly 10610^6.

Examples1

  1. Example 1

    Input
    3
    300000 200000 300000 500000
    300000 200000 500000 300000
    300000 500000 300000 200000
    1000000 1000000 0 0
    0 1000000 1000000 1000000
    999999 999999 999999 999999
    768763 148041 178147 984173
    699508 515362 534729 714381
    949704 625054 946212 951187
    
    Expected output
    Case #1: 300000 200000 300000 200000
    Case #2: IMPOSSIBLE
    Case #3: 400001 100002 100003 399994