Under construction

Still being built. Things may change

Broken Clock

Time limit30sMemory limit1024 MB

Summary
Given three unlabeled clock-hand angles and an unknown rotation, find a time before noon whose hour, minute, and second hands match them.
Level

Medium7 of 10

Topics
Math, Number theory, Implementation
Solved
No attempts yet

Problem

Emmett found an old clock in his attic. The clock is a circle with 3 hands attached to the center that rotate clockwise at constant speeds. They are called the hours hand, the minutes hand, and the seconds hand. At midnight, all hands point up. The hours hand completes a full revolution in 12 hours, the minutes hand completes a full revolution in 1 hour, and the seconds hand completes a full revolution in 1 minute. 1 hour is equal to 60 minutes, 1 minute is equal to 60 seconds, and 1 second is equal to 10910^9 nanoseconds.

For example, the clock in the picture below shows exactly 6 hours and 30 minutes after midnight. The hours hand (short black) is halfway between 6 and 7 (it has completed 6.5/12 of a revolution), the minutes hand (long black) points straight down because it has completed exactly 6 and a half full revolutions, and the seconds hand (red) points straight up because it has completed an integer number of full revolutions.

Unfortunately, the hands are broken, so they all look identical, and there is no way to know which hand is which. The clock in the picture above, with its hands broken, would look like this.

In addition, no markings remain that let Emmett know which way is up, so any rotation of the clock could be the correct one (the clock can be rotated, not reflected). To continue the example, the fully broken clock could look like this.

Emmett does know that the time was strictly before noon, that is, strictly less than 12 hours after midnight. Emmett has taken a picture of the clock. Given that picture (represented by the angles of the hands relative to one arbitrary axis), figure out what time it could correspond to.

Note that Emmett has already figured out a viable orientation of the clock in some cases (Test Set 1) and has narrowed the possible times down to a whole number of seconds (Test Sets 1 and 2) or nanoseconds (Test Set 3). See the limits section for details.

Input

The first line of the input gives the number of test cases, TT. TT lines follow. Each line describes a test case and contains three integers AA, BB, and CC: the angles of the hands, relative to an arbitrary axis and given in ticks in the clockwise direction. 1 tick is equal to 112×10−10\frac{1}{12}\times 10^{-10} degrees. This means the hours hand rotates exactly 1 tick each nanosecond, the minutes hand rotates exactly 12 ticks each nanosecond, and the seconds hand rotates exactly 720 ticks each nanosecond.

Output

For each test case, output one line containing Case #x: h m s n, where xx is the test case number (starting from 1) and hh, mm, ss, and nn are integers: hh is the number of full hours since midnight (between 0 and 11, inclusive), mm is the number of full minutes since the last full hour (between 0 and 59, inclusive), ss is the number of full seconds since the last full minute (between 0 and 59, inclusive), and nn is the number of full nanoseconds since the last full second (between 0 and 109−110^9-1, inclusive).

Limits

  • 1≤T≤1001 \le T \le 100.
  • 0≤A≤B≤C<360×12×10100 \le A \le B \le C < 360\times 12\times 10^{10}.

Examples2

  1. Example 1

    Input
    3
    0 0 0
    0 21600000000000 23400000000000
    1476000000000 2160000000000 3723000000000
    
    Expected output
    Case #1: 0 0 0 0
    Case #2: 6 30 0 0
    Case #3: 1 2 3 0
    
  2. Example 2

    Input
    3
    5400000000000 5400000000000 5400000000000
    10800000000000 32400000000000 34200000000000
    23076000000000 23760000000000 25323000000000
    
    Expected output
    Case #1: 0 0 0 0
    Case #2: 0 30 0 0
    Case #3: 1 2 3 0