The shortest code to generate the correct times on the clocks wins.
You are a seasoned time traveler and have been known to stop at many planets during your journies. Each planet rotates at a different rate and because of this, the length of a day is different than our usual 24-hour day. As a result, the planets use clocks with different numbers of hours. The hours on a clock with x hours are arranged similar to ours (1, 2, 3, ... , x) with the number rotating clockwise and x being at the top.
Additionally, each planet has a different amount of minutes in an hour, and a different number of seconds in a minute. You will be given a starting time and a number of elapsed seconds from which you must determine the ending time.
Input can be taken directly from a file passed as an argument, or as standard input. The first line of input will be the number of clocks you need to process. After that, each clock has three lines of input that contains integers in the following format:
x y z
h m s
t
The meaning of each letter is below.
x = The number of hours in a day (2 <= x <= 99)
y = The number of minutes in an hour (2 <= y <= 100)
z = The number of seconds in a minute (2 <= z <= 100)
h = The hour of the starting time (1 <= h <= x)
m = The minute of the starting time (0 <= m < y)
s = The second of the starting time (0 <= s < z)
t = The number of seconds that have elapsed
The output must be the ending time for each clock after t seconds have passed since the starting time. Your output must be formatted as standard clock time (HH:MM:SS). Numbers should be padded, when necessary, to ensure that all numbers are two-digits.
Test Cases
Input
2
5 20 10
1 10 5
2633
6 25 5
6 0 3
290
Output
04:13:08
02:08:03
Input
1
14 17 11
12 16 10
1530
Output
07:03:00
Input
2
8 40 25
3 1 15
10620
14 15 20
1 14 0
-580
Output
05:26:10
14:00:00