P8665 [Lanqiao Cup 2018 NOI Qualifier A] Flight Time
Description
Xiao h went to the United States to take part in the Lanqiao Cup international contest. Xiao h's girlfriend noticed that Xiao h left at 10 a.m. and arrived in the United States at 12 a.m., and sighed, “Planes fly so fast now, it only takes two hours to get to the United States.”
Xiao h is very afraid of supersonic flight. After careful observation, he found that both takeoff and landing times are given in local time. Since Beijing and the U.S. East Coast have a $12$-hour time difference, the flight actually takes $14$ hours in total.
Soon after, Xiao h's girlfriend went to the Middle East for an exchange program. Xiao h does not know the time difference between the Middle East and Beijing. However, Xiao h has the local takeoff and landing times for her round-trip flights. Xiao h wants to know the flight duration.
For a flight that may cross time zones, you are given the local takeoff and landing times for the outbound and return trips. Assume the flight time is the same in both directions. Find the flight duration.
Input Format
Read from standard input.
The input contains multiple test cases.
The first line contains a positive integer $T$, the number of test cases.
Each test case contains two lines: the first line is the takeoff and landing time for the outbound trip, and the second line is the takeoff and landing time for the return trip.
The time format is one of the following:
```h1:m1:s1 h2:m2:s2```
or
```h1:m1:s1 h3:m3:s3 (+1)```
or
```h1:m1:s1 h4:m4:s4 (+2)```
This means the flight takes off at local time `h1` hour `m1` minute `s1` second.
In the first format, it lands on the same day at local time `h2` hour `m2` minute `s2` second.
In the second format, it lands on the next day at local time `h3` hour `m3` minute `s3` second.
In the third format, it lands on the third day at local time `h4` hour `m4` minute `s4` second.
For all times given in the form `h:m:s` in this problem, it is guaranteed that ($0\le h\le23$, $0\le m,s\le59$).
Output Format
Write to standard output.
For each test case, output one line with a time `hh:mm:ss`, meaning the flight duration is `hh` hours `mm` minutes `ss` seconds.
Note that if a field has only one digit, you must pad it with a leading zero. For example, three hours four minutes five seconds should be written as `03:04:05`.
Explanation/Hint
It is guaranteed that the input times are valid, and the flight duration does not exceed $24$ hours.
Translated by ChatGPT 5